Permalink
Browse files

Fix OpenFilename structure in Windows widgets (#1493)

  • Loading branch information...
time-killer-games authored and JoshDreamland committed Jan 11, 2019
1 parent cbeb521 commit ba8cf49e63491caa1f582cd48c4cc42ec396a973
@@ -6,22 +6,18 @@

using std::string;

namespace enigma {

static inline string add_slash(const string& dir) {
if (dir.empty() || *dir.rbegin() != '/') return dir + '/';
return dir;
}

} // namespace enigma

namespace enigma_user {

bool set_working_directory(string dname) {
if (chdir((char *)dname.c_str()) == 0) {
char buffer[PATH_MAX + 1];
if (getcwd(buffer, PATH_MAX + 1) != NULL) {
working_directory = enigma::add_slash(buffer);
working_directory = add_slash(buffer);
return true;
}
}
@@ -31,7 +27,7 @@ bool set_working_directory(string dname) {

string environment_get_variable(string name) {
char *env = getenv((char *)name.c_str());
return env ? enigma::add_slash(env) : "";
return env ? env : "";
}

} // namespace enigma_user
@@ -62,13 +62,13 @@ HWND get_window_handle() {
return hWnd;
}

} // namespace enigma

static inline string add_slash(const string& dir) {
if (dir.empty() || *dir.rbegin() != '\\') return dir + '\\';
if (dir.empty() || dir.back() != '\\') return dir + '\\';
return dir;
}

} // namespace enigma

namespace enigma_user {

bool set_working_directory(string dname) {
@@ -77,7 +77,7 @@ bool set_working_directory(string dname) {
if (SetCurrentDirectoryW(tstr_dname.c_str()) != 0) {
WCHAR wstr_buffer[MAX_PATH + 1];
if (GetCurrentDirectoryW(MAX_PATH + 1, wstr_buffer) != 0) {
working_directory = enigma::add_slash(shorten(wstr_buffer));
working_directory = add_slash(shorten(wstr_buffer));
return true;
}
}
@@ -447,7 +447,7 @@ std::string environment_get_variable(std::string name) {
tstring tstr_name = widen(name);
GetEnvironmentVariableW(tstr_name.c_str(), (LPWSTR)&buffer, 1024);

return enigma::add_slash(shorten(buffer));
return shorten(buffer);
}

void action_webpage(const std::string &url) {
@@ -73,9 +73,17 @@ void show_error(string errortext, const bool fatal)
}

namespace enigma {
extern HINSTANCE hInstance;
extern HWND hWnd;
HWND infore;

extern HINSTANCE hInstance;
extern HWND hWnd;
HWND infore;

}

static inline string remove_slash(const string& dir) {
if (!dir.empty() && (dir.back() == '\\' || dir.back() == '/'))
return dir.substr(0, dir.length() - 1);
return dir;
}

static INT_PTR CALLBACK ShowInfoProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
@@ -481,7 +489,7 @@ string get_open_filename(string filter,string filename,string caption)
if (filter[i] == '|') filter[i] = 0;

char fn[MAX_PATH];
strcpy(fn, filename.c_str());
strcpy(fn, remove_slash(filename).c_str());

OPENFILENAME ofn;
ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = enigma::hWnd; ofn.hInstance = NULL;
@@ -508,7 +516,7 @@ string get_save_filename(string filter, string filename, string caption)
filter[i] = 0;

char fn[MAX_PATH];
strcpy(fn, filename.c_str());
strcpy(fn, remove_slash(filename).c_str());

OPENFILENAME ofn;
ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = enigma::hWnd; ofn.hInstance = NULL;

0 comments on commit ba8cf49

Please sign in to comment.