mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Fix file dialog code
This commit is contained in:
parent
371c4db1ae
commit
3ca42c11a6
2 changed files with 81 additions and 71 deletions
|
@ -1,8 +1,81 @@
|
|||
#pragma once
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <commdlg.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "file/dialog.h"
|
||||
// For desktop operating systems only. Stubbed out on Android.
|
||||
// Simplified as this will only be used in utilities / temp code.
|
||||
// An false returned means cancel;
|
||||
bool OpenFileDialog(const char *title, const char *extension, std::string *filename)
|
||||
{
|
||||
OPENFILENAME of;
|
||||
memset(&of, 0, sizeof(of));
|
||||
char buffer[512] = {0};
|
||||
of.lStructSize = sizeof(OPENFILENAME);
|
||||
of.hInstance = 0;
|
||||
of.hwndOwner = GetActiveWindow();
|
||||
|
||||
bool OpenFileDialog(const char *title, const char *extension, std::string *filename);
|
||||
bool SaveFileDialog(const char *title, const char *extension, std::string *filename);
|
||||
// These weird strings with zeroes in them can't be dealt with using normal string
|
||||
// functions, so here we go - evil hackery.
|
||||
char filter[256] = "XXX files\0*.XXX\0\0";
|
||||
memcpy(filter, extension, 3);
|
||||
memcpy(filter + 12, extension, 3);
|
||||
of.lpstrFilter = filter;
|
||||
|
||||
of.lpstrDefExt = extension;
|
||||
of.lpstrFile = buffer;
|
||||
of.nMaxFile = 511;
|
||||
|
||||
of.Flags = OFN_FILEMUSTEXIST;
|
||||
if (!GetOpenFileName(&of)) return false;
|
||||
*filename = of.lpstrFile;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SaveFileDialog(const char *title, const char *extension, std::string *filename)
|
||||
{
|
||||
OPENFILENAME of;
|
||||
memset(&of, 0, sizeof(of));
|
||||
char buffer[512] = {0};
|
||||
of.lStructSize = sizeof(OPENFILENAME);
|
||||
of.hInstance = 0;
|
||||
of.hwndOwner = GetActiveWindow();
|
||||
|
||||
// These weird strings with zeroes in them can't be dealt with using normal string
|
||||
// functions, so here we go - evil hackery.
|
||||
char filter[256] = "XXX files\0*.XXX\0\0";
|
||||
memcpy(filter, extension, 3);
|
||||
memcpy(filter + 12, extension, 3);
|
||||
of.lpstrFilter = filter;
|
||||
|
||||
of.lpstrDefExt = extension;
|
||||
of.lpstrFile = buffer;
|
||||
of.nMaxFile = 511;
|
||||
|
||||
of.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
|
||||
if (!GetSaveFileName(&of))
|
||||
return false;
|
||||
*filename = of.lpstrFile;
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <string>
|
||||
#include "base/basictypes.h"
|
||||
|
||||
bool OpenFileDialog(const char *title, const char *extension, std::string *filename)
|
||||
{
|
||||
ELOG("Asked for OpenFileDialog, not present on this platform.");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SaveFileDialog(const char *title, const char *extension, std::string *filename)
|
||||
{
|
||||
ELOG("Asked for SaveFileDialog, not present on this platform.");
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,73 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <commdlg.h>
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// For desktop operating systems only. Stubbed out on Android.
|
||||
// Simplified as this will only be used in utilities / temp code.
|
||||
// An false returned means cancel;
|
||||
bool OpenFileDialog(const char *title, const char *extension, std::string *filename)
|
||||
{
|
||||
OPENFILENAME of;
|
||||
memset(&of, 0, sizeof(of));
|
||||
char buffer[512] = {0};
|
||||
of.lStructSize = sizeof(OPENFILENAME);
|
||||
of.hInstance = 0;
|
||||
of.hwndOwner = GetActiveWindow();
|
||||
#include "file/dialog.h"
|
||||
|
||||
of.lpstrFilter = "All files (*.*)\0*.*\0\0";
|
||||
of.lpstrDefExt = extension;
|
||||
of.lpstrFile = buffer;
|
||||
|
||||
of.nMaxFile = 511;
|
||||
|
||||
of.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
||||
if (!GetOpenFileName(&of)) return false;
|
||||
*filename = of.lpstrFile;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SaveFileDialog(const char *title, const char *extension, std::string *filename)
|
||||
{
|
||||
OPENFILENAME of;
|
||||
memset(&of, 0, sizeof(of));
|
||||
char buffer[512] = {0};
|
||||
of.lStructSize = sizeof(OPENFILENAME);
|
||||
of.hInstance = 0;
|
||||
of.hwndOwner = GetActiveWindow();
|
||||
|
||||
of.lpstrFilter = "All files (*.*)\0*.*\0\0";
|
||||
of.lpstrDefExt = extension;
|
||||
of.lpstrFile = buffer;
|
||||
|
||||
of.nMaxFile = 511;
|
||||
|
||||
of.Flags = OFN_HIDEREADONLY;
|
||||
if (!GetSaveFileName(&of))
|
||||
return false;
|
||||
*filename = of.lpstrFile;
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <string>
|
||||
#include "base/basictypes.h"
|
||||
|
||||
bool OpenFileDialog(const char *title, const char *extension, std::string *filename)
|
||||
{
|
||||
ELOG("Asked for OpenFileDialog, not present on this platform.");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SaveFileDialog(const char *title, const char *extension, std::string *filename)
|
||||
{
|
||||
ELOG("Asked for SaveFileDialog, not present on this platform.");
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
bool OpenFileDialog(const char *title, const char *extension, std::string *filename);
|
||||
bool SaveFileDialog(const char *title, const char *extension, std::string *filename);
|
||||
|
|
Loading…
Add table
Reference in a new issue