fix screenshot path bugs and add some string utility functions

This commit is contained in:
zeromus 2009-07-17 04:09:07 +00:00
parent 68cf6f1e5e
commit 6297f00247
6 changed files with 74 additions and 37 deletions

View File

@ -23,6 +23,7 @@ libdesmume_a_SOURCES = \
GPU_osd.cpp GPU_osd.h \
mem.h mc.cpp mc.h \
memorystream.h \
path.h \
readwrite.cpp readwrite.h \
wifi.cpp wifi.h \
MMU.cpp MMU.h NDSSystem.cpp NDSSystem.h registers.h \

View File

@ -197,6 +197,13 @@ public:
}
}
std::string getpath(KnownPath path)
{
char temp[MAX_PATH];
SwitchPath(GET, path, temp);
return temp;
}
void getpath(KnownPath path, char *buffer)
{
SwitchPath(GET, path, buffer);
@ -242,7 +249,7 @@ public:
void formatname(char *output)
{
char file[MAX_PATH];
std::string file;
time_t now = time(NULL);
tm *time_struct = localtime(&now);
srand(now);
@ -250,7 +257,7 @@ public:
for(int i = 0; i < MAX_FORMAT;i++)
{
char *c = &screenshotFormat[i];
char tmp[MAX_PATH];
char tmp[MAX_PATH] = {0};
if(*c == '%')
{
@ -294,9 +301,9 @@ public:
break;
tmp[j-i]='\0';
}
strcat(file, tmp);
file += tmp;
}
strncpy(output, file, MAX_PATH);
strncpy(output, file.c_str(), MAX_PATH);
}
enum ImageFormat

View File

@ -3,9 +3,40 @@
#include "xstring.h"
#include <string>
//a vc-style substring operation (very kind and lenient)
std::string strsub(const std::string& str, int pos, int len) {
int strlen = str.size();
if(strlen==0) return str; //empty strings always return empty strings
if(pos>=strlen) return str; //if you start past the end of the string, return the entire string. this is unusual, but there you have it
//clipping
if(pos<0) {
len += pos;
pos = 0;
}
if (pos+len>=strlen)
len=strlen-pos+1;
//return str.str().substr(pos,len);
return str.substr(pos,len);
}
std::string strmid(const std::string& str, int pos, int len) { return strsub(str,pos,len); }
std::string strleft(const std::string& str, int len) { return strsub(str,0,len); }
std::string strright(const std::string& str, int len) { return len ? strsub(str,str.size()-len,len) : ""; }
std::string toupper(const std::string& str)
{
std::string ret = str;
for(u32 i=0;i<str.size();i++)
ret[i] = toupper(ret[i]);
return ret;
}
///Upper case routine. Returns number of characters modified
int str_ucase(char *str) {
unsigned int i=0,j=0; //mbg merge 7/17/06 changed to unsigned int
u32 i=0,j=0;
while (i < strlen(str)) {
if ((str[i] >= 'a') && (str[i] <= 'z')) {
@ -20,7 +51,7 @@ int str_ucase(char *str) {
///Lower case routine. Returns number of characters modified
int str_lcase(char *str) {
unsigned int i=0,j=0; //mbg merge 7/17/06 changed to unsigned int
u32 i=0,j=0;
while (i < strlen(str)) {
if ((str[i] >= 'A') && (str[i] <= 'Z')) {
@ -38,7 +69,7 @@ int str_lcase(char *str) {
///Removes whitespace from left side of string, depending on the flags set (See STRIP_x definitions in xstring.h)
///Returns number of characters removed
int str_ltrim(char *str, int flags) {
unsigned int i=0; //mbg merge 7/17/06 changed to unsigned int
u32 i=0;
while (str[0]) {
if ((str[0] != ' ') || (str[0] != '\t') || (str[0] != '\r') || (str[0] != '\n')) break;
@ -69,7 +100,7 @@ int str_ltrim(char *str, int flags) {
///Removes whitespace from right side of string, depending on the flags set (See STRIP_x definitions in xstring.h)
///Returns number of characters removed
int str_rtrim(char *str, int flags) {
unsigned int i=0; //mbg merge 7/17/06 changed to unsigned int
u32 i=0;
while (strlen(str)) {
if ((str[strlen(str)-1] != ' ') ||
@ -103,7 +134,7 @@ int str_rtrim(char *str, int flags) {
///Removes whitespace depending on the flags set (See STRIP_x definitions in xstring.h)
///Returns number of characters removed, or -1 on error
int str_strip(char *str, int flags) {
unsigned int i=0,j=0; //mbg merge 7/17/06 changed to unsigned int
u32 i=0,j=0;
char *astr,chr;
if (!strlen(str)) return -1;
@ -130,7 +161,7 @@ int str_strip(char *str, int flags) {
///Replaces all instances of 'search' with 'replace'
///Returns number of characters modified
int chr_replace(char *str, char search, char replace) {
unsigned int i=0,j=0; //mbg merge 7/17/06 changed to unsigned int
u32 i=0,j=0;
while (i < strlen(str)) {
if (str[i] == search) {
@ -148,7 +179,7 @@ int chr_replace(char *str, char search, char replace) {
///Replaces all instances of 'search' with 'replace'
///Returns number of sub-strings modified, or -1 on error
int str_replace(char *str, char *search, char *replace) {
unsigned int i=0,j=0; //mbg merge 7/17/06 changed to unsigned int
u32 i=0,j=0;
int searchlen,replacelen;
char *astr;

View File

@ -28,6 +28,12 @@ int str_strip(char *str, int flags);
int chr_replace(char *str, char search, char replace);
int str_replace(char *str, char *search, char *replace);
std::string strsub(const std::string& str, int pos, int len);
std::string strmid(const std::string& str, int pos, int len);
std::string strleft(const std::string& str, int len);
std::string strright(const std::string& str, int len);
std::string toupper(const std::string& str);
int HexStringToBytesLength(const std::string& str);
int Base64StringToBytesLength(const std::string& str);
std::string u32ToHexString(u32 val);

View File

@ -1042,6 +1042,10 @@
RelativePath="..\OGLRender.h"
>
</File>
<File
RelativePath="..\path.h"
>
</File>
<File
RelativePath=".\pathsettings.cpp"
>

View File

@ -83,57 +83,45 @@ void CopyCustomKeys (SCustomKeys *dst, const SCustomKeys *src)
void HK_OpenROM(int) {OpenFile();}
void HK_PrintScreen(int param)
{
char filename[MAX_PATH];
char outFilename[MAX_PATH];
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = MainWindow->getHWnd();
ofn.lpstrFilter = "png file (*.png)\0*.png\0Bmp file (*.bmp)\0*.bmp\0Any file (*.*)\0*.*\0\0";
ofn.lpstrTitle = "Print Screen Save As";
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFile = outFilename;
ofn.Flags = OFN_OVERWRITEPROMPT;
ZeroMemory(filename, sizeof(filename));
path.getpath(path.SCREENSHOTS, filename);
std::string filename = path.getpath(path.SCREENSHOTS);
char file[MAX_PATH];
ZeroMemory(file, sizeof(file));
path.formatname(file);
strcat(filename, file);
int len = strlen(filename);
if(len > MAX_PATH - 4)
filename[MAX_PATH - 4] = '\0';
filename += file;
if(path.imageformat() == path.PNG)
{
strcat(filename, ".png");
filename += ".png";
ofn.lpstrDefExt = "png";
ofn.nFilterIndex = 1;
}
else if(path.imageformat() == path.BMP)
{
strcat(filename, ".bmp");
filename += ".bmp";
ofn.lpstrDefExt = "bmp";
ofn.nFilterIndex = 2;
}
ofn.lpstrFile = filename;
GetSaveFileName(&ofn);
strcpy(outFilename,filename.c_str());
if(!GetSaveFileName(&ofn))
return;
char *ptr = strrchr(filename,'.');//look for the last . in the filename
if ( ptr != 0 ) {
if (( strcmp ( ptr, ".BMP" ) == 0 ) ||
( strcmp ( ptr, ".bmp" ) == 0 ))
{
NDS_WriteBMP(filename);
}
if (( strcmp ( ptr, ".PNG" ) == 0 ) ||
( strcmp ( ptr, ".png" ) == 0 ))
{
NDS_WritePNG(filename);
}
}
if(toupper(strright(filename,4)) == ".BMP")
NDS_WriteBMP(filename.c_str());
else if(toupper(strright(filename,4)) == ".BMP")
NDS_WriteBMP(filename.c_str());
}
void HK_StateSaveSlot(int num)