1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#include "MainFrame.h"
#include "clPersistenceManager.h"
#include "wxTerminalOptions.h"
#include <iostream>
#include <thread>
#include <wx/app.h>
#include <wx/cmdline.h>
#include <wx/event.h>
#include <wx/image.h>
#include <wx/persist.h>
//#ifdef __WXMSW__
// void RedirectIOToConsole()
//{
// AllocConsole();
// freopen("CON", "wb", stdout);
// freopen("CON", "wb", stderr);
// freopen("CON", "r", stdin); // Note: "r", not "w"
//}
//#endif
static const wxCmdLineEntryDesc cmdLineDesc[] = {
// Switches
{ wxCMD_LINE_SWITCH, "v", "version", "Print current version", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, "h", "help", "Print usage", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_SWITCH, "w", "wait", "Wait for any key to be pressed before exiting", wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL },
// Options
{ wxCMD_LINE_OPTION, "p", "print-tty", "Print the terminals tty (*nix only) into file", wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, "t", "title", "Set the console title", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, "d", "working-directory", "Set the working directory", wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, "c", "command", "Command to execute", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_OPTION, "f", "file", "File contains command to execute", wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_NONE }
};
class MyPersistenceManager : public wxPersistenceManager
{
wxFileConfig* m_config = nullptr;
public:
MyPersistenceManager()
{
wxFileName localFile(wxStandardPaths::Get().GetUserDataDir(), "persistency.ini");
m_config = new wxFileConfig("codelite-terminal", "CodeLite", localFile.GetFullPath());
}
~MyPersistenceManager() { wxDELETE(m_config); }
wxConfigBase* GetConfig() const { return m_config; }
};
// Define the MainApp
class MainApp : public wxApp
{
MyPersistenceManager* m_persistency = nullptr;
public:
MainApp() {}
virtual ~MainApp() { wxDELETE(m_persistency); }
virtual bool OnInit()
{
SetAppName("codelite-terminal");
wxFileName configDir(wxStandardPaths::Get().GetUserDataDir(), "");
configDir.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
m_persistency = new MyPersistenceManager();
wxPersistenceManager::Set(*m_persistency);
wxTerminalOptions& m_options = wxTerminalOptions::Get();
// m_persistencManager = new clPersistenceManager();
// wxPersistenceManager::Set(*m_persistencManager);
#ifdef __WXMSW__
typedef BOOL WINAPI (*SetProcessDPIAwareFunc)();
HINSTANCE user32Dll = LoadLibrary(L"User32.dll");
if(user32Dll) {
SetProcessDPIAwareFunc pFunc = (SetProcessDPIAwareFunc)GetProcAddress(user32Dll, "SetProcessDPIAware");
if(pFunc) {
pFunc();
}
FreeLibrary(user32Dll);
}
#endif
wxCmdLineParser parser(wxApp::argc, wxApp::argv);
parser.SetDesc(cmdLineDesc);
const wxArrayString& argv = wxApp::argv.GetArguments();
for(const wxString& arg : argv) {
if(arg.StartsWith("--wait")) {
m_options.SetWaitOnExit(true);
} else if(arg.StartsWith("--help")) {
// Print usage and exit
std::cout << parser.GetUsageString() << std::endl;
wxExit();
} else if(arg.StartsWith("--title")) {
wxString title = arg.AfterFirst('=');
m_options.SetTitle(title);
} else if(arg.StartsWith("--print-tty")) {
m_options.SetPrintTTY(true);
wxString ttyfile = arg.AfterFirst('=');
m_options.SetTtyfile(ttyfile);
} else if(arg.StartsWith("--working-directory")) {
wxString wd = arg.AfterFirst('=');
m_options.SetWorkingDirectory(wd);
} else if(arg.StartsWith("--command")) {
wxString cmd = arg.AfterFirst('=');
m_options.SetCommand(cmd);
} else if(arg.StartsWith("--file")) {
wxString cmdfile = arg.AfterFirst('=');
m_options.SetCommandFromFile(cmdfile);
} else if(arg.StartsWith("--log")) {
wxString logfile = arg.AfterFirst('=');
m_options.SetLogfile(logfile);
}
}
// Add the common image handlers
wxImage::AddHandler(new wxPNGHandler);
wxImage::AddHandler(new wxJPEGHandler);
MainFrame* mainFrame = new MainFrame(NULL);
SetTopWindow(mainFrame);
return GetTopWindow()->Show();
}
};
DECLARE_APP(MainApp)
IMPLEMENT_APP(MainApp)
// int main(int argc, char** argv)
//{
// // MyWxApp derives from wxApp
// wxApp::SetInstance(new MainApp());
// wxEntryStart(argc, argv);
// wxTheApp->OnInit();
// wxTheApp->OnRun();
// wxTheApp->OnExit();
// wxEntryCleanup();
// return 0;
//}
|