| 1 |
#include "apis/ProfileManager.h" |
| 2 |
#include "apis/PlatformProfileManager.h" |
| 3 |
|
| 4 |
#include <wx/cmdline.h> |
| 5 |
#include <wx/filename.h> |
| 6 |
#include <wx/stream.h> |
| 7 |
#include <wx/txtstrm.h> |
| 8 |
#include <wx/wfstream.h> |
| 9 |
|
| 10 |
const static wxCmdLineEntryDesc CmdLineOptions[] = { |
| 11 |
{wxCMD_LINE_PARAM, NULL, NULL, wxT_2("<operation>"), wxCMD_LINE_VAL_STRING, 0}, |
| 12 |
{wxCMD_LINE_PARAM, NULL, NULL, wxT_2("<file>"), wxCMD_LINE_VAL_STRING, 0}, |
| 13 |
{wxCMD_LINE_NONE}, |
| 14 |
}; |
| 15 |
|
| 16 |
/** RegistryHelper is a executable helper for wxLauncher that will allow it to |
| 17 |
set the required registry keys on Windows Vista and Windows 7 because they both by |
| 18 |
default virtualize the registry so that the use of HKLM it redirected to HKCU. |
| 19 |
|
| 20 |
Registry Virtualization in Windows Vista <http://msdn.microsoft.com/en-us/library/bb530198.aspx> |
| 21 |
|
| 22 |
The executable that this app is compiled into *must* *not* have a UAC manifest |
| 23 |
so that Win7 and WinVista will Virtualize its access to HKLM. Not having the |
| 24 |
UAC manifest allows us to write into the per user virtual location where FSO |
| 25 |
is looking because it also does not have a UAC manifest. This |
| 26 |
virtualiszation also allows us to write the cmdline_fso.cfg file to the |
| 27 |
correct location (data/cmdline_fso.cfg) if FSO has been installed into Program Files. */ |
| 28 |
class RegistryHelper : public wxApp { |
| 29 |
public: |
| 30 |
virtual int OnRun(); |
| 31 |
virtual void OnInitCmdLine(wxCmdLineParser &parser); |
| 32 |
virtual bool OnCmdLineParsed(wxCmdLineParser &parser); |
| 33 |
private: |
| 34 |
wxFileName file; |
| 35 |
enum Operation { |
| 36 |
None, |
| 37 |
Push, |
| 38 |
Pull, |
| 39 |
}; |
| 40 |
Operation op; |
| 41 |
}; |
| 42 |
|
| 43 |
IMPLEMENT_APP(RegistryHelper) |
| 44 |
|
| 45 |
int RegistryHelper::OnRun() { |
| 46 |
wxFile stdoutfile(wxFile::fd_stdout); |
| 47 |
if ( !file.IsOk() ) { |
| 48 |
return ProMan::FileIsNotOK; |
| 49 |
} |
| 50 |
|
| 51 |
wxFileConfig* config; |
| 52 |
if (this->op == Push) { |
| 53 |
if ( !file.FileExists() ) { |
| 54 |
return ProMan::InputFileDoesNotExist; |
| 55 |
} |
| 56 |
wxFFileInputStream f(file.GetFullPath()); |
| 57 |
config = new wxFileConfig(f); |
| 58 |
} else { |
| 59 |
config = new wxFileConfig(); |
| 60 |
} |
| 61 |
|
| 62 |
if (this->op == Push) { |
| 63 |
return RegistryPushProfile(config); |
| 64 |
} else if (this->op == Pull) { |
| 65 |
ProMan::RegistryCodes ret; |
| 66 |
ret = RegistryPullProfile(config); |
| 67 |
if ( ret == ProMan::NoError ) { |
| 68 |
wxFFileOutputStream f(file.GetFullPath()); |
| 69 |
if (config->Save(f)) { |
| 70 |
return ProMan::NoError; |
| 71 |
} else { |
| 72 |
return ProMan::UnknownError; |
| 73 |
} |
| 74 |
} else { |
| 75 |
return ret; |
| 76 |
} |
| 77 |
} else { |
| 78 |
return ProMan::UnknownError; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
void RegistryHelper::OnInitCmdLine(wxCmdLineParser &parser) { |
| 83 |
parser.SetSwitchChars(wxT_2("-")); // always use - even on windows |
| 84 |
parser.SetLogo(wxT_2("wxLauncher Registry Tool")); |
| 85 |
parser.SetDesc(CmdLineOptions); |
| 86 |
} |
| 87 |
|
| 88 |
bool RegistryHelper::OnCmdLineParsed(wxCmdLineParser &parser) { |
| 89 |
wxString operation = parser.GetParam(0).MakeLower(); |
| 90 |
if (operation.StartsWith(wxT_2("push")) ) { |
| 91 |
this->op = Push; |
| 92 |
} else if ( operation.StartsWith(wxT_2("pull")) ) { |
| 93 |
this->op = Pull; |
| 94 |
} else { |
| 95 |
parser.Usage(); |
| 96 |
return false; |
| 97 |
} |
| 98 |
file.Assign(parser.GetParam(1)); |
| 99 |
return true; |
| 100 |
} |