mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-09 09:56:35 +02:00
Data in user data directory (backwards-compatible)
This commit is contained in:
committed by
Tamás Bálint Misius
parent
9fcf780c78
commit
a9f07dc5b0
@@ -29,8 +29,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#ifdef MACOSX
|
#ifdef MACOSX
|
||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
@@ -154,12 +154,12 @@ void blit(pixel * vid)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void RecreateWindow();
|
void RecreateWindow();
|
||||||
int SDLOpen()
|
void SDLOpen()
|
||||||
{
|
{
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
|
fprintf(stderr, "Initializing SDL (video subsystem): %s\n", SDL_GetError());
|
||||||
return 1;
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
RecreateWindow();
|
RecreateWindow();
|
||||||
@@ -197,9 +197,6 @@ int SDLOpen()
|
|||||||
SDL_SetWindowIcon(sdl_window, icon);
|
SDL_SetWindowIcon(sdl_window, icon);
|
||||||
SDL_FreeSurface(icon);
|
SDL_FreeSurface(icon);
|
||||||
#endif
|
#endif
|
||||||
atexit(SDL_Quit);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLSetScreen(int scale_, bool resizable_, bool fullscreen_, bool altFullscreen_, bool forceIntegerScaling_)
|
void SDLSetScreen(int scale_, bool resizable_, bool fullscreen_, bool altFullscreen_, bool forceIntegerScaling_)
|
||||||
@@ -617,23 +614,6 @@ void SigHandler(int signal)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChdirToDataDirectory()
|
|
||||||
{
|
|
||||||
#ifdef MACOSX
|
|
||||||
FSRef ref;
|
|
||||||
OSType folderType = kApplicationSupportFolderType;
|
|
||||||
char path[PATH_MAX];
|
|
||||||
|
|
||||||
FSFindFolder( kUserDomain, folderType, kCreateFolder, &ref );
|
|
||||||
|
|
||||||
FSRefMakePath( &ref, (UInt8*)&path, PATH_MAX );
|
|
||||||
|
|
||||||
std::string tptPath = std::string(path) + "/The Powder Toy";
|
|
||||||
mkdir(tptPath.c_str(), 0755);
|
|
||||||
chdir(tptPath.c_str());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr int SCALE_MAXIMUM = 10;
|
constexpr int SCALE_MAXIMUM = 10;
|
||||||
constexpr int SCALE_MARGIN = 30;
|
constexpr int SCALE_MARGIN = 30;
|
||||||
|
|
||||||
@@ -661,6 +641,14 @@ int main(int argc, char * argv[])
|
|||||||
currentHeight = WINDOWH;
|
currentHeight = WINDOWH;
|
||||||
|
|
||||||
|
|
||||||
|
// https://bugzilla.libsdl.org/show_bug.cgi?id=3796
|
||||||
|
if (SDL_Init(0) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
atexit(SDL_Quit);
|
||||||
|
|
||||||
std::map<ByteString, ByteString> arguments = readArguments(argc, argv);
|
std::map<ByteString, ByteString> arguments = readArguments(argc, argv);
|
||||||
|
|
||||||
if(arguments["ddir"].length())
|
if(arguments["ddir"].length())
|
||||||
@@ -670,7 +658,27 @@ int main(int argc, char * argv[])
|
|||||||
chdir(arguments["ddir"].c_str());
|
chdir(arguments["ddir"].c_str());
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
ChdirToDataDirectory();
|
{
|
||||||
|
#ifdef WIN
|
||||||
|
struct _stat s;
|
||||||
|
if(_stat("powder.pref", &s) != 0)
|
||||||
|
#else
|
||||||
|
struct stat s;
|
||||||
|
if(stat("powder.pref", &s) != 0)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
char *ddir = SDL_GetPrefPath(NULL, "The Powder Toy");
|
||||||
|
if(ddir)
|
||||||
|
{
|
||||||
|
#ifdef WIN
|
||||||
|
_chdir(ddir);
|
||||||
|
#else
|
||||||
|
chdir(ddir);
|
||||||
|
#endif
|
||||||
|
SDL_free(ddir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scale = Client::Ref().GetPrefInteger("Scale", 1);
|
scale = Client::Ref().GetPrefInteger("Scale", 1);
|
||||||
resizable = Client::Ref().GetPrefBool("Resizable", false);
|
resizable = Client::Ref().GetPrefBool("Resizable", false);
|
||||||
|
Reference in New Issue
Block a user