forked from 0ad/0ad
Let Atlas find data files when cwd is not binaries/system. Fixes #481.
This was SVN commit r7412.
This commit is contained in:
parent
38feae61fb
commit
5a5a269b93
@ -23,15 +23,14 @@
|
||||
#include "wx/filename.h"
|
||||
#include "wx/dir.h"
|
||||
|
||||
static wxString systemDir;
|
||||
static wxString dataDir;
|
||||
static wxString g_DataDir;
|
||||
|
||||
AtObj Datafile::ReadList(const char* section)
|
||||
{
|
||||
const wxString relativePath (_T("tools/atlas/lists.xml"));
|
||||
|
||||
wxFileName filename (relativePath, wxPATH_UNIX);
|
||||
filename.MakeAbsolute(dataDir);
|
||||
filename.MakeAbsolute(g_DataDir);
|
||||
|
||||
if (! filename.FileExists())
|
||||
{
|
||||
@ -65,22 +64,28 @@ bool Datafile::SlurpFile(const wxString& filename, std::string& out)
|
||||
void Datafile::SetSystemDirectory(const wxString& dir)
|
||||
{
|
||||
wxFileName sys (dir);
|
||||
systemDir = sys.GetPath();
|
||||
wxString systemDir = sys.GetPath();
|
||||
|
||||
wxFileName data (_T("../data/"), wxPATH_UNIX);
|
||||
data.MakeAbsolute(systemDir);
|
||||
dataDir = data.GetPath();
|
||||
g_DataDir = data.GetPath();
|
||||
}
|
||||
|
||||
void Datafile::SetDataDirectory(const wxString& dir)
|
||||
{
|
||||
wxFileName data (dir);
|
||||
g_DataDir = data.GetPath();
|
||||
}
|
||||
|
||||
wxString Datafile::GetDataDirectory()
|
||||
{
|
||||
return dataDir;
|
||||
return g_DataDir;
|
||||
}
|
||||
|
||||
wxArrayString Datafile::EnumerateDataFiles(const wxString& dir, const wxString& filter)
|
||||
{
|
||||
wxFileName d (dir);
|
||||
d.MakeAbsolute(dataDir);
|
||||
d.MakeAbsolute(g_DataDir);
|
||||
|
||||
wxArrayString files;
|
||||
wxDir::GetAllFiles(d.GetPath(), &files, filter, wxDIR_FILES);
|
||||
|
@ -29,6 +29,10 @@ namespace Datafile
|
||||
// relative to the current working directory.
|
||||
void SetSystemDirectory(const wxString& dir);
|
||||
|
||||
// Specify the location of .../binaries/data, as an absolute path, or
|
||||
// relative to the current working directory.
|
||||
void SetDataDirectory(const wxString& dir);
|
||||
|
||||
// Returns the location of .../binaries/data. (TODO (eventually): replace
|
||||
// this with a proper VFS-aware system.)
|
||||
wxString GetDataDirectory();
|
||||
|
@ -109,6 +109,13 @@ ATLASDLLIMPEXP void Atlas_SetMessagePasser(MessagePasser* passer)
|
||||
g_MessagePasser = passer;
|
||||
}
|
||||
|
||||
bool g_HasSetDataDirectory = false;
|
||||
ATLASDLLIMPEXP void Atlas_SetDataDirectory(const wchar_t* path)
|
||||
{
|
||||
Datafile::SetDataDirectory(path);
|
||||
g_HasSetDataDirectory = true;
|
||||
}
|
||||
|
||||
ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type)
|
||||
{
|
||||
// Initialise libxml2
|
||||
@ -186,10 +193,13 @@ public:
|
||||
// Initialise the global config file
|
||||
wxConfigBase::Set(new wxConfig(_T("Atlas Editor"), _T("Wildfire Games")));
|
||||
|
||||
// Assume that the .exe is located in .../binaries/system. (We can't
|
||||
// just use the cwd, since that isn't correct when being executed by
|
||||
// dragging-and-dropping onto the program in Explorer.)
|
||||
Datafile::SetSystemDirectory(argv[0]);
|
||||
if (! g_HasSetDataDirectory)
|
||||
{
|
||||
// Assume that the .exe is located in .../binaries/system. (We can't
|
||||
// just use the cwd, since that isn't correct when being executed by
|
||||
// dragging-and-dropping onto the program in Explorer.)
|
||||
Datafile::SetSystemDirectory(argv[0]);
|
||||
}
|
||||
|
||||
// Display the appropriate window
|
||||
wxFrame* frame;
|
||||
|
@ -23,6 +23,7 @@
|
||||
namespace AtlasMessage { class MessagePasser; }
|
||||
|
||||
ATLASDLLIMPEXP void Atlas_SetMessagePasser(AtlasMessage::MessagePasser*);
|
||||
ATLASDLLIMPEXP void Atlas_SetDataDirectory(const wchar_t* path);
|
||||
ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type);
|
||||
|
||||
ATLASDLLIMPEXP void Atlas_GLSetCurrent(void* context);
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "ps/DllLoader.h"
|
||||
#include "ps/Filesystem.h"
|
||||
#include "ps/Profile.h"
|
||||
#include "ps/GameSetup/Paths.h"
|
||||
|
||||
using namespace AtlasMessage;
|
||||
|
||||
@ -46,6 +47,7 @@ namespace AtlasMessage
|
||||
|
||||
// Loaded from DLL:
|
||||
void (*Atlas_StartWindow)(const wchar_t* type);
|
||||
void (*Atlas_SetDataDirectory)(const wchar_t* path);
|
||||
void (*Atlas_SetMessagePasser)(MessagePasser*);
|
||||
void (*Atlas_GLSetCurrent)(void* cavas);
|
||||
void (*Atlas_GLSwapBuffers)(void* canvas);
|
||||
@ -68,11 +70,11 @@ static InputProcessor g_Input;
|
||||
static GameLoopState state;
|
||||
GameLoopState* g_GameLoop = &state;
|
||||
|
||||
|
||||
static void* LaunchWindow(void* data)
|
||||
{
|
||||
const wchar_t* windowName = reinterpret_cast<const wchar_t*>(data);
|
||||
debug_SetThreadName("atlas_window");
|
||||
|
||||
const wchar_t* windowName = reinterpret_cast<const wchar_t*>(data);
|
||||
Atlas_StartWindow(windowName);
|
||||
return NULL;
|
||||
}
|
||||
@ -101,6 +103,7 @@ bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
|
||||
{
|
||||
dll.LoadSymbol("Atlas_StartWindow", Atlas_StartWindow);
|
||||
dll.LoadSymbol("Atlas_SetMessagePasser", Atlas_SetMessagePasser);
|
||||
dll.LoadSymbol("Atlas_SetDataDirectory", Atlas_SetDataDirectory);
|
||||
dll.LoadSymbol("Atlas_GLSetCurrent", Atlas_GLSetCurrent);
|
||||
dll.LoadSymbol("Atlas_GLSwapBuffers", Atlas_GLSwapBuffers);
|
||||
dll.LoadSymbol("Atlas_NotifyEndOfFrame", Atlas_NotifyEndOfFrame);
|
||||
@ -118,6 +121,10 @@ bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
|
||||
// Pass our message handler to Atlas
|
||||
Atlas_SetMessagePasser(&msgPasser);
|
||||
|
||||
// Tell Atlas the location of the data directory
|
||||
const Paths paths(args);
|
||||
Atlas_SetDataDirectory(paths.RData().string().c_str());
|
||||
|
||||
// Register all the handlers for message which might be passed back
|
||||
RegisterHandlers();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user