2005-05-19 04:46:42 +02:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include "DLLInterface.h"
|
|
|
|
|
|
|
|
#include "Datafile.h"
|
|
|
|
#include "ActorEditor/ActorEditor.h"
|
|
|
|
#include "ColourTester/ColourTester.h"
|
2005-06-25 04:21:26 +02:00
|
|
|
#include "ScenarioEditor/ScenarioEditor.h"
|
2005-09-12 22:04:26 +02:00
|
|
|
#include "FileConverter/FileConverter.h"
|
|
|
|
#include "ArchiveViewer/ArchiveViewer.h"
|
2005-06-25 04:21:26 +02:00
|
|
|
|
2005-06-28 01:04:34 +02:00
|
|
|
#include "GameInterface/MessagePasser.h"
|
2005-05-19 04:46:42 +02:00
|
|
|
|
|
|
|
#include "wx/config.h"
|
2005-09-12 22:04:26 +02:00
|
|
|
#include "wx/debugrpt.h"
|
2005-05-19 04:46:42 +02:00
|
|
|
|
|
|
|
// Global variables, to remember state between DllMain and StartWindow and OnInit
|
|
|
|
wxString g_InitialWindowType;
|
|
|
|
HINSTANCE g_Module;
|
|
|
|
bool g_IsLoaded = false;
|
|
|
|
|
|
|
|
|
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
|
|
|
|
{
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
g_Module = hModule;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
if (g_IsLoaded)
|
|
|
|
{
|
|
|
|
wxEntryCleanup();
|
|
|
|
g_IsLoaded = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
using namespace AtlasMessage;
|
2005-05-19 04:46:42 +02:00
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
MessagePasser<mCommand>* AtlasMessage::g_MessagePasser_Command = NULL;
|
|
|
|
MessagePasser<mInput>* AtlasMessage::g_MessagePasser_Input = NULL;
|
|
|
|
|
|
|
|
ATLASDLLIMPEXP void Atlas_SetMessagePasser(MessagePasser<mCommand>* handler_cmd, MessagePasser<mInput>* handler_in)
|
2005-06-25 04:21:26 +02:00
|
|
|
{
|
2005-07-03 18:25:48 +02:00
|
|
|
g_MessagePasser_Command = handler_cmd;
|
|
|
|
g_MessagePasser_Input = handler_in;
|
2005-06-25 04:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ATLASDLLIMPEXP void Atlas_StartWindow(wchar_t* type)
|
2005-05-19 04:46:42 +02:00
|
|
|
{
|
|
|
|
g_InitialWindowType = type;
|
|
|
|
wxEntry(g_Module);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class wxDLLApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool OnInit()
|
|
|
|
{
|
2005-09-12 22:04:26 +02:00
|
|
|
if (! wxIsDebuggerRunning())
|
|
|
|
wxHandleFatalExceptions();
|
|
|
|
|
2005-05-19 04:46:42 +02:00
|
|
|
// 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]);
|
|
|
|
|
2005-09-12 22:04:26 +02:00
|
|
|
// Display the appropriate window
|
2005-05-19 04:46:42 +02:00
|
|
|
wxFrame* frame;
|
2005-09-12 22:04:26 +02:00
|
|
|
#define MAYBE(t) if (g_InitialWindowType == _T(#t)) frame = new t(NULL); else
|
|
|
|
MAYBE(ActorEditor)
|
|
|
|
MAYBE(ColourTester)
|
|
|
|
MAYBE(ScenarioEditor)
|
|
|
|
MAYBE(FileConverter)
|
|
|
|
MAYBE(ArchiveViewer)
|
|
|
|
#undef MAYBE
|
|
|
|
// else
|
2005-05-19 04:46:42 +02:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(_("Internal error: invalid window type"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->Show();
|
|
|
|
SetTopWindow(frame);
|
|
|
|
|
2005-09-12 22:04:26 +02:00
|
|
|
AtlasWindow* win = wxDynamicCast(frame, AtlasWindow);
|
|
|
|
if (win)
|
2005-05-19 04:46:42 +02:00
|
|
|
{
|
2005-09-12 22:04:26 +02:00
|
|
|
// One argument => argv[1] is probably a filename to open
|
|
|
|
if (argc > 1)
|
2005-05-19 04:46:42 +02:00
|
|
|
{
|
2005-09-12 22:04:26 +02:00
|
|
|
wxChar* filename = argv[1];
|
|
|
|
|
|
|
|
if (filename[0] != _T('-')) // ignore -options
|
2005-06-25 04:21:26 +02:00
|
|
|
{
|
2005-09-12 22:04:26 +02:00
|
|
|
if (wxFile::Exists(filename))
|
|
|
|
{
|
2005-06-25 04:21:26 +02:00
|
|
|
win->OpenFile(filename);
|
2005-09-12 22:04:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
wxLogError(_("Cannot find file '%s'"), filename);
|
2005-06-25 04:21:26 +02:00
|
|
|
}
|
2005-05-19 04:46:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2005-09-12 22:04:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool OpenDirectory(const wxString& dir)
|
|
|
|
{
|
|
|
|
// Code largely copied from wxLaunchDefaultBrowser:
|
|
|
|
// (TODO: portability)
|
|
|
|
|
|
|
|
typedef HINSTANCE (WINAPI *LPShellExecute)(HWND hwnd, const wxChar* lpOperation,
|
|
|
|
const wxChar* lpFile,
|
|
|
|
const wxChar* lpParameters,
|
|
|
|
const wxChar* lpDirectory,
|
|
|
|
INT nShowCmd);
|
|
|
|
|
|
|
|
HINSTANCE hShellDll = ::LoadLibrary(_T("shell32.dll"));
|
|
|
|
if (hShellDll == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LPShellExecute lpShellExecute =
|
|
|
|
(LPShellExecute) ::GetProcAddress(hShellDll,
|
|
|
|
wxString(_T("ShellExecute")
|
|
|
|
#ifdef _UNICODE
|
|
|
|
_T("W")
|
|
|
|
#else
|
|
|
|
_T("A")
|
|
|
|
#endif
|
|
|
|
).mb_str(wxConvLocal));
|
|
|
|
|
|
|
|
if (lpShellExecute == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*HINSTANCE nResult =*/ (*lpShellExecute)(NULL, _T("explore"), dir.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
|
|
|
// ignore return value, since we're not going to do anything if this fails
|
|
|
|
|
|
|
|
::FreeLibrary(hShellDll);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnFatalException()
|
|
|
|
{
|
|
|
|
wxDebugReport report;
|
|
|
|
wxDebugReportPreviewStd preview;
|
|
|
|
|
|
|
|
report.AddAll();
|
|
|
|
|
|
|
|
if (preview.Show(report))
|
|
|
|
{
|
|
|
|
wxString dir = report.GetDirectory(); // save the string, since it gets cleared by Process
|
|
|
|
report.Process();
|
|
|
|
OpenDirectory(dir);
|
|
|
|
}
|
|
|
|
}
|
2005-05-19 04:46:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|