//Send a message int Api_Send( Message* msg, time_t timeout ) { if( (size_t)msg + sizeof(Message) >= KERNEL_BASE ) return -ERR_WRONGARG; return IpcCall( msg, 0, timeout); }
bool CslApp::OnInit() { SetAppName(wxString(CSL_NAME_SHORT_STR).Lower()); #if defined(__WXMSW__) wxCrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif #if CSL_DEBUG < 1 #if wxUSE_DEBUGREPORT && wxUSE_ON_FATAL_EXCEPTION ::wxHandleFatalExceptions(true); #endif #endif wxString ipcCmd; const wxString cwd = ::DirName(::wxPathOnly(argv[0])); static const wxCmdLineEntryDesc cmdLineDesc[] = { { wxCMD_LINE_SWITCH, NULL, wxT_2("version"), wxTRANSLATE("show version"), wxCMD_LINE_VAL_NONE, 0 }, { wxCMD_LINE_SWITCH, wxT_2("h"), wxT_2("help"), wxTRANSLATE("show this help"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, { wxCMD_LINE_OPTION, wxT_2("d"), wxT_2("datadir"), wxTRANSLATE("add data dir"), wxCMD_LINE_VAL_STRING, 0 }, { wxCMD_LINE_OPTION, wxT_2("p"), wxT_2("plugindir"), wxTRANSLATE("add plugin dir"), wxCMD_LINE_VAL_STRING, 0 }, { wxCMD_LINE_OPTION, wxT_2("q"), wxT_2("homedir"), wxTRANSLATE("set home dir"), wxCMD_LINE_VAL_STRING, 0 }, { wxCMD_LINE_PARAM, NULL, NULL, wxTRANSLATE("IPC command"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE } }; wxString sOpt; wxCmdLineParser parser(cmdLineDesc, argc, argv); switch (parser.Parse()) { case -1: // help return true; case 0: if (parser.Found(wxT("version"))) { wxPrintf(wxT("%s\n"), CSL_VERSION_STR); return true; } if (parser.Found(wxT("q"), &sOpt)) m_home = ::DirName(sOpt, cwd); if (parser.Found(wxT("d"), &sOpt)) AddDataDir(sOpt, cwd); if (parser.Found(wxT("p"), &sOpt)) AddPluginDir(sOpt, cwd); break; default: // syntax error return true; } if (parser.GetParamCount()) ipcCmd = parser.GetParam(0); if (m_home.IsEmpty()) m_home = ::DirName(wxStandardPaths::Get().GetUserDataDir()); if (!wxFileName::DirExists(m_home)) { if (!wxFileName::Mkdir(m_home, 0700, wxPATH_MKDIR_FULL)) { wxMessageBox(wxString::Format(_("Failed to create the home dir '%s'."), m_home.c_str()), _("Fatal error!"), wxICON_ERROR); return false; } } else if (!wxFileName::IsDirWritable(m_home)) { wxMessageBox(wxString::Format(_("Home dir '%s' isn't writable."), m_home.c_str()), _("Fatal error!"), wxICON_ERROR); return false; } CSL_LOG_DEBUG("using home dir: %s\n", U2C(m_home)); AddDataDir(m_home, cwd); #ifdef PROJECTDIR if (::wxDirExists(wxT(PROJECTDIR))) AddDataDir(wxT(PROJECTDIR), cwd); #endif #ifdef __WXMAC__ AddDataDir(wxT("../Resources"), cwd); #else AddDataDir(cwd); #endif #ifdef DATADIR if (cwd!=m_home) AddDataDir(wxT(DATADIR), cwd); #endif AddPluginDir(m_home, cwd); #ifdef __WXMAC__ AddPluginDir(wxT(".."), cwd); #else AddPluginDir(cwd); #endif #ifdef BUILDDIR if (::wxDirExists(wxT(BUILDDIR))) AddPluginDir(wxT(BUILDDIR), cwd); #endif #ifdef PKGLIBDIR if (cwd!=m_home) AddPluginDir(wxT(PKGLIBDIR)); #endif m_locale.Init(wxLANGUAGE_DEFAULT, #if wxCHECK_VERSION(2, 9, 0) wxLOCALE_LOAD_DEFAULT #else wxLOCALE_CONV_ENCODING #endif //wxCHECK_VERSION ); #ifndef LOCALEDIR #ifdef __WXMSW__ m_locale.AddCatalogLookupPathPrefix(cwd+wxT("\\locale")); #else #ifdef __WXMAC__ m_locale.AddCatalogLookupPathPrefix(cwd+wxT("../Resources")); #endif //__WXMAC__ #endif //__WXMSW__ #else m_locale.AddCatalogLookupPathPrefix(wxT(LOCALEDIR)); #endif //LOCALEDIR if (m_locale.AddCatalog(wxString(CSL_NAME_SHORT_STR).Lower())) m_lang=m_locale.GetCanonicalName(); #ifdef __WXMAC__ wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), 1); // enables Command-H, Command-M and Command-Q at least when not in fullscreen wxSetEnv(wxT("SDL_SINGLEDISPLAY"),wxT("1")); wxSetEnv(wxT("SDL_ENABLEAPPEVENTS"),wxT("1")); // TODO wxApp::SetExitOnFrameDelete(false); // register event handler for URI schemes AEInstallEventHandler(kInternetEventClass, kAEGetURL, NewAEEventHandlerUPP((AEEventHandlerProcPtr)MacCallbackGetUrl), 0, false); #endif //__WXMAC__ m_single = new wxSingleInstanceChecker; wxString lock = wxString::Format(wxT("%s-%s.%s"), CSL_NAME_SHORT_STR, wxGetUserId().c_str(), #ifdef __WXMSW__ GetHomeDir(wxPATH_UNIX).c_str() #else wxT("lock") #endif ).Lower(); if (m_single->Create(lock, m_home) && m_single->IsAnotherRunning()) { IpcCall(ipcCmd.IsEmpty() ? wxT("show") : ipcCmd); return true; } m_engine = new CslEngine; wxInitAllImageHandlers(); CslFrame* frame = new CslFrame; if (m_shutdown!=CSL_SHUTDOWN_NONE) return true; SetTopWindow(frame); frame->Show(); if (!ipcCmd.IsEmpty()) IpcCall(ipcCmd, frame); return true; }
bool CslApp::OnInit() { m_engine=NULL; m_single=NULL; m_shutdown=CSL_SHUTDOWN_NONE; ::wxSetWorkingDirectory(wxPathOnly(wxTheApp->argv[0])); g_basePath=::wxGetCwd(); m_locale.Init(wxLANGUAGE_DEFAULT,wxLOCALE_CONV_ENCODING); m_locale.AddCatalogLookupPathPrefix(LOCALEPATH); #ifdef __WXGTK__ m_locale.AddCatalogLookupPathPrefix(g_basePath+wxString(wxT("/lang"))); #endif if (m_locale.AddCatalog(CSL_NAME_SHORT_STR)) m_lang=m_locale.GetCanonicalName(); #ifdef __WXMAC__ wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"),1); //enables Command-H, Command-M and Command-Q at least when not in fullscreen wxSetEnv(wxT("SDL_SINGLEDISPLAY"),wxT("1")); wxSetEnv(wxT("SDL_ENABLEAPPEVENTS"),wxT("1")); //TODO wxApp::SetExitOnFrameDelete(false); //register event handler for URI schemes AEInstallEventHandler(kInternetEventClass,kAEGetURL, NewAEEventHandlerUPP((AEEventHandlerProcPtr)MacCallbackGetUrl),0,false); #endif wxString uri; for (wxInt32 i=1;i<wxApp::argc;i++) { uri=wxApp::argv[i]; if (!uri.StartsWith(CSL_URI_SCHEME_STR)) uri.Empty(); } wxString lock=wxString::Format(wxT(".%s-%s.lock"),CSL_NAME_SHORT_STR,wxGetUserId().c_str()); m_single=new wxSingleInstanceChecker(lock); if (m_single->IsAnotherRunning()) { if (uri.IsEmpty()) uri=wxT("show"); IpcCall(uri); return true; } m_engine=new CslEngine; wxInitAllImageHandlers(); CslFrame* frame=new CslFrame(NULL,wxID_ANY,wxEmptyString,wxDefaultPosition); SetTopWindow(frame); frame->Show(); if (!uri.IsEmpty()) IpcCall(uri,frame); return true; }