bool CEpgOptions::LoadLogoFile() { if (m_fSaveLogoFile && m_szLogoFileName[0]!='\0') { CAppMain &App=GetAppClass(); CLogoManager &LogoManager=App.LogoManager; TCHAR szFileName[MAX_PATH]; if (!GetAbsolutePath(m_szLogoFileName,szFileName,lengthof(szFileName))) return false; if (::PathFileExists(szFileName)) { App.AddLog(TEXT("ロゴデータを \"%s\" から読み込みます..."),szFileName); if (!LogoManager.LoadLogoFile(szFileName)) { App.AddLog(CLogItem::TYPE_ERROR,TEXT("ロゴファイルの読み込みでエラーが発生しました。")); return false; } } if (::lstrlen(szFileName)+4<MAX_PATH) { ::lstrcat(szFileName,TEXT(".ini")); if (!::PathFileExists(szFileName)) { // 以前のバージョンとの互換用 ::GetModuleFileName(NULL,szFileName,lengthof(szFileName)); ::PathRenameExtension(szFileName,TEXT(".logo.ini")); if (!::PathFileExists(szFileName)) return false; } App.AddLog(TEXT("ロゴ設定を \"%s\" から読み込みます..."),szFileName); LogoManager.LoadLogoIDMap(szFileName); } } return true; }
bool CEpgOptions::AsyncLoadEpgFile(CEpgProgramList *pEpgList,CEpgFileLoadEventHandler *pEventHandler) { if (m_fSaveEpgFile) { TCHAR szFileName[MAX_PATH]; if (!GetAbsolutePath(m_szEpgFileName,szFileName,lengthof(szFileName))) return false; if (::PathFileExists(szFileName)) { GetAppClass().AddLog(TEXT("EPG データを \"%s\" から読み込みます..."),szFileName); EpgLoadInfo *pInfo=new EpgLoadInfo; pInfo->pList=pEpgList; pInfo->pEventHandler=pEventHandler; ::lstrcpy(pInfo->szFileName,szFileName); m_hLoadThread=(HANDLE)::_beginthreadex(NULL,0,EpgFileLoadThread,pInfo,0,NULL); if (m_hLoadThread==NULL) { delete pInfo; //return pEpgList->LoadFromFile(szFileName); return false; } } } return true; }
bool CEpgOptions::SaveEpgFile(CEpgProgramList *pEpgList) { bool fOK=true; if (m_fSaveEpgFile) { TCHAR szFileName[MAX_PATH]; if (!pEpgList->IsUpdated()) return true; if (!GetAbsolutePath(m_szEpgFileName,szFileName,lengthof(szFileName))) return false; if (pEpgList->NumServices()>0) { GetAppClass().AddLog(TEXT("EPG データを \"%s\" に保存します..."),szFileName); fOK=pEpgList->SaveToFile(szFileName); if (!fOK) ::DeleteFile(szFileName); } else { /* fOK=::DeleteFile(szFileName) || ::GetLastError()==ERROR_FILE_NOT_FOUND; */ } } return fOK; }
void SharedLibraryHandle::Load(const std::string& name) { #ifdef US_BUILD_SHARED_LIBS if (m_Handle) throw std::logic_error(std::string("Library already loaded: ") + name); std::string libPath = GetAbsolutePath(name); #ifdef US_PLATFORM_POSIX m_Handle = dlopen(libPath.c_str(), RTLD_LAZY | RTLD_GLOBAL); if (!m_Handle) { const char* err = dlerror(); throw std::runtime_error(err ? std::string(err) : libPath); } #else m_Handle = LoadLibrary(libPath.c_str()); if (!m_Handle) { std::string errMsg = "Loading "; errMsg.append(libPath).append("failed with error: ").append(GetLastErrorStr()); throw std::runtime_error(errMsg); } #endif #endif m_Name = name; }
bool GetClrFilesAbsolutePath(const char* currentExePath, const char* clrFilesPath, std::string& clrFilesAbsolutePath) { std::string clrFilesRelativePath; const char* clrFilesPathLocal = clrFilesPath; if (clrFilesPathLocal == nullptr) { // There was no CLR files path specified, use the folder of the corerun/coreconsole if (!GetDirectory(currentExePath, clrFilesRelativePath)) { perror("Failed to get directory from argv[0]"); return false; } clrFilesPathLocal = clrFilesRelativePath.c_str(); // TODO: consider using an env variable (if defined) as a fall-back. // The windows version of the corerun uses core_root env variable } if (!GetAbsolutePath(clrFilesPathLocal, clrFilesAbsolutePath)) { perror("Failed to convert CLR files path to absolute path"); return false; } return true; }
bool CEpgOptions::SaveLogoFile() { if (m_fSaveLogoFile && m_szLogoFileName[0]!='\0') { CAppMain &App=GetAppClass(); CLogoManager &LogoManager=App.LogoManager; TCHAR szFileName[MAX_PATH]; if (!GetAbsolutePath(m_szLogoFileName,szFileName,lengthof(szFileName))) return false; if (!::PathFileExists(szFileName) || LogoManager.IsLogoDataUpdated()) { App.AddLog(TEXT("ロゴデータを \"%s\" に保存します..."),szFileName); if (!LogoManager.SaveLogoFile(szFileName)) { App.AddLog(CLogItem::TYPE_ERROR,TEXT("ロゴファイルの保存でエラーが発生しました。")); return false; } } if (::lstrlen(szFileName)+4<MAX_PATH) { ::lstrcat(szFileName,TEXT(".ini")); if (!::PathFileExists(szFileName) || LogoManager.IsLogoIDMapUpdated()) { App.AddLog(TEXT("ロゴ設定を \"%s\" に保存します..."),szFileName); LogoManager.SaveLogoIDMap(szFileName); } } } return true; }
/** * \brief This is the function where CG beings * * \param argc number of arguments * \param argv pointer to char arrays where * where the passed arguments are stored * in the process * \return This always returns 0. If * some errors appear, take a look * at the Logfile. * */ int main(int argc, char *argv[]) { #if SDL_VERSION_ATLEAST(2, 0, 0) #ifdef ANDROID SDL_SetMainReady( ); #endif #endif // Check if CG should look into a given directory if(argc >= 1) { binary_dir = argv[0]; size_t slashpos = findLastPathSep(binary_dir); if(slashpos != std::string::npos) { binary_dir.erase(slashpos); binary_dir = SystemNativeToUtf8(binary_dir); } else { binary_dir = "."; } } else { warnings << "Binary-argument not given, assuming current dir" << endl; binary_dir = "."; } binary_dir = GetAbsolutePath(binary_dir); InitThreadPool(); InitSearchPaths(); g_pLogFile->CreateLogfile("CGLog.html"); // The Game Class instance is the main class managing whole // interpreter instance. TODO: It should be a singleton CGame Game; //////////////////////////// // Initialize Game Engine // //////////////////////////// if( Game.init( argc, argv ) ) { /////////////////////// // Start Game Engine // /////////////////////// Game.run(); } std::cout << "Thank you very much for playing this game!" << std::endl; UnInitThreadPool(); return 0; }
int corerun(const int argc, const char* argv[]) { // Make sure we have a full path for argv[0]. std::string argv0AbsolutePath; if (!GetAbsolutePath(argv[0], argv0AbsolutePath)) { perror("Could not get full path to current executable"); return -1; } // Get name of self and containing folder (typically the MacOS folder) int lastSlashPos = argv0AbsolutePath.rfind('/'); std::string appName = argv0AbsolutePath.substr(lastSlashPos+1); std::string appFolder = argv0AbsolutePath.substr(0, lastSlashPos); // Strip off "MacOS" to get to the "Contents" folder std::string contentsFolder; if (!GetDirectory(appFolder.c_str(), contentsFolder)) { perror("Could not get Contents folder"); return -1; } // Append standard locations std::string clrFilesAbsolutePath = contentsFolder + "/CoreClrBundle"; std::string managedFolderAbsolutePath = contentsFolder + "/ManagedBundle/"; std::string managedAssemblyAbsolutePath = managedFolderAbsolutePath + appName + ".exe"; // Pass all command line arguments to managed executable const char** managedAssemblyArgv = argv; int managedAssemblyArgc = argc; // Check if the specified managed assembly file exists struct stat sb; if (stat(managedAssemblyAbsolutePath.c_str(), &sb) == -1) { perror(managedAssemblyAbsolutePath.c_str()); return -1; } // Verify that the managed assembly path points to a file if (!S_ISREG(sb.st_mode)) { fprintf(stderr, "The specified managed assembly is not a file\n"); return -1; } // And go... int exitCode = ExecuteManagedAssembly( argv0AbsolutePath.c_str(), clrFilesAbsolutePath.c_str(), managedAssemblyAbsolutePath.c_str(), managedAssemblyArgc, managedAssemblyArgv); return exitCode; }
bool CSVFile::GetFileList(const TCHAR *lr2Path, std::vector<std::wstring> &resArr) { TCHAR absolutePath[256]; GetAbsolutePath(lr2Path, absolutePath); // split path int i; for (i=0; i<wcslen(absolutePath); i++) { if (absolutePath[i] == L'*') break; } if (i == wcslen(absolutePath)) { // just return if (boost::filesystem::exists(absolutePath)) { resArr.push_back(absolutePath); } else { return false; } } else { // split path absolutePath[i] = 0; std::wstring path_first = absolutePath; std::wstring path_last = absolutePath+i+1; // is we searching directory or file? bool searchFile = false; if (path_last.find(L'\\') == std::wstring::npos) { searchFile = true; } // find all and add boost::filesystem::path dir(path_first); boost::filesystem::directory_iterator end_it; if (boost::filesystem::exists(path_first)) { for (boost::filesystem::directory_iterator it(dir); it!=end_it; ++it) { if ((searchFile && boost::filesystem::is_regular_file(it->status())) || (!searchFile && !boost::filesystem::is_regular_file(it->status()))) { std::wstring path = (*it).path().wstring(); if (searchFile) { // check ext if (!boost::algorithm::ends_with(path, path_last)) continue; } else { // add last path // and check existance path += path_last; if (!boost::filesystem::exists(path)) continue; } resArr.push_back(path); } } } else { return false; } } }
String Texture2DAssetFile::GetImageFilepath() const { String contents = FileReader::GetContents(GetAbsolutePath()); XMLNode *xmlInfo = XMLNode::FromString(contents); String result = ""; if (xmlInfo) { result = xmlInfo->GetString("ImageFilepath"); delete xmlInfo; } return result; }
void Load(const std::string& name) { if (m_Handle) throw std::logic_error(std::string("Library already loaded: ") + name); std::string libPath = GetAbsolutePath(name); #ifdef PLATFORM_UNIX m_Handle = dlopen(libPath.c_str(), RTLD_LAZY | RTLD_GLOBAL); if (!m_Handle) { const char* err = dlerror(); throw std::runtime_error(err ? std::string(err) : libPath); } #else m_Handle = LoadLibrary(libPath.c_str()); if (!m_Handle) { // Retrieve the system error message for the last-error code LPVOID lpMsgBuf; LPVOID lpDisplayBuf; DWORD dw = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); // Display the error message and exit the process lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)libPath.c_str()) + 50) * sizeof(TCHAR)); StringCchPrintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(TCHAR), TEXT("Loading %s failed with error %d: %s"), libPath.c_str(), dw, lpMsgBuf); std::string errMsg((LPCTSTR)lpDisplayBuf); LocalFree(lpMsgBuf); LocalFree(lpDisplayBuf); throw std::runtime_error(errMsg); } #endif m_Name = name; }
bool CEpgOptions::LoadEpgFile(CEpgProgramList *pEpgList) { bool fOK=true; if (m_fSaveEpgFile) { TCHAR szFileName[MAX_PATH]; if (!GetAbsolutePath(m_szEpgFileName,szFileName,lengthof(szFileName))) return false; if (::PathFileExists(szFileName)) { GetAppClass().AddLog(TEXT("EPG データを \"%s\" から読み込みます..."),szFileName); fOK=pEpgList->LoadFromFile(szFileName); } } return fOK; }
bool CEpgOptions::LoadEDCBData() { bool fOK=true; if (m_fUseEDCBData && m_szEDCBDataFolder[0]!='\0') { TCHAR szPath[MAX_PATH]; if (!GetAbsolutePath(m_szEDCBDataFolder,szPath,lengthof(szPath))) return false; CEpgDataLoader Loader; fOK=Loader.Load(szPath); } return fOK; }
bool CEpgOptions::AsyncLoadEDCBData(CEDCBDataLoadEventHandler *pEventHandler) { bool fOK=true; if (m_fUseEDCBData && m_szEDCBDataFolder[0]!='\0') { TCHAR szPath[MAX_PATH]; if (!GetAbsolutePath(m_szEDCBDataFolder,szPath,lengthof(szPath))) return false; delete m_pEpgDataLoader; m_pEpgDataLoader=new CEpgDataLoader; fOK=m_pEpgDataLoader->LoadAsync(szPath,pEventHandler); } return fOK; }
bool CONFIG::ProcessLine(CONFIG::iterator & section, std::string & linestr) { linestr = Trim(linestr); linestr = Strip(linestr, '\r'); linestr = Strip(linestr, '\n'); //remove comments std::string::size_type commentpos = linestr.find("#", 0); if (commentpos < linestr.length()) { linestr = linestr.substr(0, commentpos); } linestr = Trim(linestr); //only continue if not a blank line or comment-only line if (linestr.length() > 0) { if (linestr.find("=", 0) < linestr.length()) { //find the name part std::string::size_type equalpos = linestr.find("=", 0); std::string name = linestr.substr(0, equalpos); equalpos++; std::string val = linestr.substr(equalpos, linestr.length() - equalpos); name = Trim(name); val = Trim(val); //only continue if valid if (name.length() > 0 && val.length() > 0) { section->second[name] = val; } else if (!SUPPRESS_ERROR) { //std::cout << "a line started with an equal sign or ended with an equal sign:" << std::endl // << linestr << std::endl; return false; } } else if (linestr.find("include ") == 0) { //configfile include std::string dir; std::string relpath = linestr.erase(0, 8); std::string::size_type pos = filename.rfind('/'); if (pos != std::string::npos) dir = filename.substr(0, pos); std::string path = GetAbsolutePath(dir, relpath); bool include_load_success = Load(path); if (!SUPPRESS_ERROR && !include_load_success) { //std::cout << "the included file failed to load, bail" << std::endl; return false; } } else { //section header std::string section_name; section_name = Strip(linestr, '['); section_name = Strip(section_name, ']'); section_name = Trim(section_name); // subsection size_t n = section_name.rfind('.'); if (n != std::string::npos) { std::string parent = section_name.substr(0, n); std::string child = section_name.substr(n+1); /* SECTIONMAP::const_iterator parent_iter = sections.find(parent); if (!SUPPRESS_ERROR && (parent_iter == sections.end())) { std::cout << "warning: parent section " << parent << " doesn't exist. adding an empty one." << std::endl; return false; } SECTION::const_iterator child_iter = parent_iter->second.find(child); if (!SUPPRESS_ERROR && (child_iter != parent_iter->second.end())) { std::cout << "child already exists, this must be a duplicate section. error" << std::endl; return false; } */ sections[parent][child] = section_name; } /* SECTIONMAP::const_iterator already_exists = sections.find(section_name); if (!SUPPRESS_ERROR && (already_exists != sections.end())) { std::cout << "section " << section_name << " already exists, duplicate section in the file, error" << std::endl; return false; /// this shouldn't be an error case because included files will import sections. /// find a way to mark which sections were included, or keep a list of sections imported during this load? /// or perhaps just don't worry about it? } */ section = sections.insert(std::pair<std::string, SECTION>(section_name, SECTION())).first; } } return true; }
bool StartWebServer() { //LOG_INFO << "Starting Mongoose " << mg_version() << " web server"; qDebug() << "Starting Mongoose " << mg_version() << " web server"; ////json_value* appSettings = GetApplicationSettings(); // 404_handler ////std::string _404_handler = (*appSettings)["web_server"]["404_handler"]; std::string _404_handler = "/pretty-urls.php"; // Ip address and port. If port was set to 0, then real port // will be known only after the webserver was started. ////std::string ipAddress = (*appSettings)["web_server"]["listen_on"][0]; std::string ipAddress = "127.0.0.1"; ////std::string port = (*appSettings)["web_server"]["listen_on"][1]; std::string port = "8080"; #if 0x0 long portInt = (*appSettings)["web_server"]["listen_on"][1]; if (portInt) port = IntToString(portInt); if (ipAddress.empty()) { ipAddress = "127.0.0.1"; } if (port.empty()) { port = "0"; } #endif // WWW directory from settings. #if 0x0 std::string wwwDirectory = (*appSettings)["web_server"]["www_directory"]; if (wwwDirectory.empty()) { wwwDirectory = "www"; } wwwDirectory = GetAbsolutePath(wwwDirectory); #else std::string wwwDirectory = "E:\\phpdesktop-chrome-31.8-php-5.6.1\\www"; #endif //LOG_INFO << "WWW directory: " << wwwDirectory; qDebug() << "WWW directory: " << wwwDirectory; // Index files from settings. #if 0x0 const json_value indexFilesArray = (*appSettings)["web_server"]["index_files"]; std::string indexFiles; for (int i = 0; i < 32; i++) { const char* file = indexFilesArray[i]; if (strlen(file)) { if (indexFiles.length()) indexFiles.append(","); indexFiles.append(file); } } if (indexFiles.empty()) indexFiles = "index.html,index.php"; #else std::string indexFiles = "index.html,index.php"; #endif //LOG_INFO << "Index files: " << indexFiles; qDebug() << "Index files: " << indexFiles; // CGI interpreter from settings. #if 0x0 std::string cgiInterpreter = (*appSettings)["web_server"]["cgi_interpreter"]; if (cgiInterpreter.empty()) { cgiInterpreter = "php\\php-cgi.exe"; } cgiInterpreter = GetAbsolutePath(cgiInterpreter); #else std::string cgiInterpreter = "E:\\phpdesktop-chrome-31.8-php-5.6.1\\php\\php-cgi.exe"; #endif //LOG_INFO << "CGI interpreter: " << cgiInterpreter; qDebug() << "CGI interpreter: " << cgiInterpreter; // CGI extensions from settings. #if 0x0 const json_value cgiExtensions = (*appSettings)["web_server"]["cgi_extensions"]; std::string cgiPattern; for (int i = 0; i < 32; i++) { const char* extension = cgiExtensions[i]; if (strlen(extension)) { if (cgiPattern.length()) cgiPattern.append("|"); cgiPattern.append("**.").append(extension).append("$"); } } if (cgiPattern.empty()) cgiPattern = "**.php$"; #else std::string cgiPattern = "**.php$"; #endif //LOG_INFO << "CGI pattern: " << cgiPattern; qDebug() << "CGI pattern: " << cgiPattern; // Hide files patterns. #if 0x0 const json_value hide_files = (*appSettings)["web_server"]["hide_files"]; std::string hide_files_patterns = ""; for (int i = 0; i < 100; i++) { const char* pattern = hide_files[i]; if (strlen(pattern)) { if (hide_files_patterns.length()) hide_files_patterns.append("|"); hide_files_patterns.append("**/").append(pattern).append("$"); } } #else std::string hide_files_patterns = ""; #endif //LOG_INFO << "Hide files patterns: " << hide_files_patterns; qDebug() << "Hide files patterns: " << hide_files_patterns; // Temp directory. ////std::string cgi_temp_dir = (*appSettings)["web_server"]["cgi_temp_dir"]; ////cgi_temp_dir = GetAbsolutePath(cgi_temp_dir); std::string cgi_temp_dir = ""; QDir cgi_temp_dir_q(QString::fromStdString(cgi_temp_dir)); ////if (!cgi_temp_dir.length() || !DirectoryExists(cgi_temp_dir)) { if (!cgi_temp_dir.length() || !cgi_temp_dir_q.exists()) { if (cgi_temp_dir.length()) { //LOG_WARNING << "cgi_temp_dir directory does not exist: " << cgi_temp_dir; qDebug() << "cgi_temp_dir directory does not exist: " << cgi_temp_dir; } ////cgi_temp_dir.assign(GetAnsiTempDirectory()); cgi_temp_dir = QDir::tempPath().toStdString(); } // CGI environment variables. std::string cgiEnvironment = ""; cgiEnvironment.append("TMP=").append(cgi_temp_dir).append(","); cgiEnvironment.append("TEMP=").append(cgi_temp_dir).append(","); cgiEnvironment.append("TMPDIR=").append(cgi_temp_dir).append(","); // Mongoose sets SERVER_NAME to "mydomain.com" cgiEnvironment.append("SERVER_NAME=").append(ipAddress).append(","); #if 0x0 // Let users identify whether web app runs in a normal browser // or a phpdesktop browser. cgiEnvironment.append("PHPDESKTOP_VERSION=").append(GetPhpDesktopVersion()); // Environment from application args if (g_cgiEnvironmentFromArgv.length()) { cgiEnvironment.append(",").append(g_cgiEnvironmentFromArgv); } #endif //LOG_INFO << "CGI environment variables set: " << cgiEnvironment; qDebug() << "CGI environment variables set: " << cgiEnvironment; // Mongoose web server. std::string listening_ports = ipAddress + ":" + port; const char* options[] = { "document_root", wwwDirectory.c_str(), "listening_ports", listening_ports.c_str(), "index_files", indexFiles.c_str(), "cgi_interpreter", cgiInterpreter.c_str(), "cgi_pattern", cgiPattern.c_str(), "cgi_environment", cgiEnvironment.c_str(), "404_handler", _404_handler.c_str(), "hide_files_patterns", hide_files_patterns.c_str(), NULL }; // Globals. g_wwwDirectory = wwwDirectory; g_cgiInterpreter = cgiInterpreter; mg_callbacks callbacks = {0}; callbacks.log_message = &log_message; callbacks.end_request = &end_request; g_mongooseContext = mg_start(&callbacks, NULL, options); if (g_mongooseContext == NULL) return false; // When port was set to 0 then a random free port was assigned. g_webServerPort = mg_get_listening_port(g_mongooseContext); g_webServerIpAddress = ipAddress; g_webServerUrl = "http://" + ipAddress + ":" + std::to_string(g_webServerPort) + "/"; //LOG_INFO << "Web server url: " << g_webServerUrl; qDebug() << "Web server url: " << g_webServerUrl; return true; }
/** * \brief This is the function where CG beings * * \param argc number of arguments * \param argv pointer to char arrays where * where the passed arguments are stored * in the process * \return This always returns 0. If * some errors appear, take a look * at the Logfile. * */ int main(int argc, char *argv[]) { #if SDL_VERSION_ATLEAST(2, 0, 0) #ifdef ANDROID SDL_SetMainReady( ); #endif #endif // Check if CG should look into a given directory std::string binary_dir; if(argc >= 1) { binary_dir = argv[0]; size_t slashpos = findLastPathSep(binary_dir); if(slashpos != std::string::npos) { binary_dir.erase(slashpos); binary_dir = SystemNativeToUtf8(binary_dir); } else { binary_dir = "."; } } else { warnings << "Binary-argument not given, assuming current dir" << endl; binary_dir = "."; } SetBinaryDir( GetAbsolutePath(binary_dir) ); InitThreadPool(); InitSearchPaths(g_pSettings->getConfigFileName()); gLogging.CreateLogfile("CGLog.html", APP_NAME, CGVERSION); // Check if there are settings on the PC, otherwise use defaults. if(!g_pSettings->loadDrvCfg()) { //m_firsttime = true; gLogging.textOut(RED,"First time message: CG didn't find the driver config file. "); gLogging.textOut(RED,"However, it generated some default values and will save them now.\n"); g_pSettings->saveDrvCfg(); } gLogging.textOut(GREEN,"Loading game options...\n"); if(!g_pSettings->loadGameOptions()) { gLogging.textOut(RED,"Cannot do loading defaults...\n"); g_pSettings->loadDefaultGameCfg(); } // Init the Game sound g_pSound->init(); //////////////////////////////////////////////////// // Initialize CG and run the main cycle if worthy // //////////////////////////////////////////////////// if( gApp.init( argc, argv ) ) { //////////////////////////////// // Set GameLauncher as Engine // //////////////////////////////// gApp.setEngine(new CGameLauncher(false)); ////////////////////////////// // Run the Commander Genius // ////////////////////////////// gApp.runMainCycle(); } g_pSettings->saveDispCfg(); UnInitThreadPool(); return 0; }
bfs::path GetAbsolutePath(const std::string& path) { return GetAbsolutePath(bfs::path(path)); }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrCmdLine, int nCmdShow) { g_hInstance = hInstance; json_value* appSettings = GetApplicationSettings(); if (GetApplicationSettingsError().length()) { std::string error = GetApplicationSettingsError(); error.append("\nApplication will terminate immediately. "); FatalError(NULL, error); } // Debugging options. bool show_console = (*appSettings)["debugging"]["show_console"]; bool subprocess_show_console = (*appSettings)["debugging"]["subprocess_show_console"]; std::string log_level = (*appSettings)["debugging"]["log_level"]; std::string log_file = (*appSettings)["debugging"]["log_file"]; log_file = GetAbsolutePath(log_file); // Initialize logging. if (std::wstring(lpstrCmdLine).find(L"--type=") != std::string::npos) { // This is a subprocess. InitializeLogging(subprocess_show_console, log_level, log_file); } else { // Main browser process. InitializeLogging(show_console, log_level, log_file); } // Command line arguments LPWSTR *argv; int argc; argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (argv) { for (int i = 0; i < argc; i++) { std::string argument = WideToUtf8(std::wstring(argv[i])); size_t pos = argument.find("="); if (pos != std::string::npos) { std::string name = argument.substr(0, pos); std::string value = argument.substr(pos+1, std::string::npos); if (name == "--cgi-environment" && value.length()) { g_cgiEnvironmentFromArgv.assign(value); } } } } else { LOG_WARNING << "CommandLineToArgvW() failed"; } // CEF subprocesses. CefMainArgs main_args(hInstance); CefRefPtr<App> app(new App); int exit_code = CefExecuteProcess(main_args, app.get(), NULL); if (exit_code >= 0) { ShutdownLogging(); return exit_code; } LOG_INFO << "--------------------------------------------------------"; LOG_INFO << "Started application"; if (log_file.length()) LOG_INFO << "Logging to: " << log_file; else LOG_INFO << "No logging file set"; LOG_INFO << "Log level = " << FILELog::ToString(FILELog::ReportingLevel()); // Main window title option. std::string main_window_title = (*appSettings)["main_window"]["title"]; if (main_window_title.empty()) main_window_title = GetExecutableName(); // Single instance guid option. const char* single_instance_guid = (*appSettings)["application"]["single_instance_guid"]; if (single_instance_guid && single_instance_guid[0] != 0) { int guidSize = strlen(single_instance_guid) + 1; g_singleInstanceApplicationGuid = new wchar_t[guidSize]; Utf8ToWide(single_instance_guid, g_singleInstanceApplicationGuid, guidSize); } if (g_singleInstanceApplicationGuid && g_singleInstanceApplicationGuid[0] != 0) { g_singleInstanceApplication.Initialize( g_singleInstanceApplicationGuid); if (g_singleInstanceApplication.IsRunning()) { HWND hwnd = FindWindow(g_singleInstanceApplicationGuid, NULL); if (hwnd) { if (IsIconic(hwnd)) ShowWindow(hwnd, SW_RESTORE); SetForegroundWindow(hwnd); return 0; } } } // Window class name. if (g_singleInstanceApplicationGuid) { swprintf_s(g_windowClassName, _countof(g_windowClassName), L"%s", g_singleInstanceApplicationGuid); } else { swprintf_s(g_windowClassName, _countof(g_windowClassName), L"%s", Utf8ToWide(GetExecutableName()).c_str()); } if (!StartWebServer()) { FatalError(NULL, "Error while starting an internal local server.\n" "Application will terminate immediately."); } CefSettings cef_settings; // log_file std::string chrome_log_file = (*appSettings)["chrome"]["log_file"]; chrome_log_file = GetAbsolutePath(chrome_log_file); CefString(&cef_settings.log_file) = chrome_log_file; // log_severity std::string chrome_log_severity = (*appSettings)["chrome"]["log_severity"]; cef_log_severity_t log_severity = LOGSEVERITY_DEFAULT; if (chrome_log_severity == "verbose") { log_severity = LOGSEVERITY_VERBOSE; } else if (chrome_log_severity == "info") { log_severity = LOGSEVERITY_INFO; } else if (chrome_log_severity == "warning") { log_severity = LOGSEVERITY_WARNING; } else if (chrome_log_severity == "error") { log_severity = LOGSEVERITY_ERROR; } else if (chrome_log_severity == "error-report") { log_severity = LOGSEVERITY_ERROR_REPORT; } else if (chrome_log_severity == "disable") { log_severity = LOGSEVERITY_DISABLE; } cef_settings.log_severity = log_severity; // cache_path std::string cache_path = (*appSettings)["chrome"]["cache_path"]; cache_path = GetAbsolutePath(cache_path); CefString(&cef_settings.cache_path) = cache_path; // remote_debugging_port // A value of -1 will disable remote debugging. int remote_debugging_port = static_cast<long>( (*appSettings)["chrome"]["remote_debugging_port"]); if (remote_debugging_port == 0) { remote_debugging_port = random(49152, 65535+1); int i = 100; while (((i--) > 0) && remote_debugging_port == GetWebServerPort()) { remote_debugging_port = random(49152, 65535+1); } } if (remote_debugging_port > 0) { LOG_INFO << "remote_debugging_port = " << remote_debugging_port; cef_settings.remote_debugging_port = remote_debugging_port; } // Sandbox support cef_settings.no_sandbox = true; CefInitialize(main_args, cef_settings, app.get(), NULL); CreateMainWindow(hInstance, nCmdShow, main_window_title); CefRunMessageLoop(); CefShutdown(); LOG_INFO << "Ended application"; LOG_INFO << "--------------------------------------------------------"; ShutdownLogging(); return 0; }
int corerun(const int argc, const char* argv[]) { const char* clrFilesPath; const char* managedAssemblyPath; const char** managedAssemblyArgv; int managedAssemblyArgc; if (!ParseArguments( argc, argv, &clrFilesPath, &managedAssemblyPath, &managedAssemblyArgc, &managedAssemblyArgv)) { // Invalid command line return -1; } // Check if the specified managed assembly file exists struct stat sb; if (stat(managedAssemblyPath, &sb) == -1) { perror("Managed assembly not found"); return -1; } // Verify that the managed assembly path points to a file if (!S_ISREG(sb.st_mode)) { fprintf(stderr, "The specified managed assembly is not a file\n"); return -1; } // Make sure we have a full path for argv[0]. std::string argv0AbsolutePath; if (!GetAbsolutePath(argv[0], argv0AbsolutePath)) { perror("Could not get full path"); return -1; } std::string clrFilesAbsolutePath; if(!GetClrFilesAbsolutePath(argv0AbsolutePath.c_str(), clrFilesPath, clrFilesAbsolutePath)) { return -1; } std::string managedAssemblyAbsolutePath; if (!GetAbsolutePath(managedAssemblyPath, managedAssemblyAbsolutePath)) { perror("Failed to convert managed assembly path to absolute path"); return -1; } int exitCode = ExecuteManagedAssembly( argv0AbsolutePath.c_str(), clrFilesAbsolutePath.c_str(), managedAssemblyAbsolutePath.c_str(), managedAssemblyArgc, managedAssemblyArgv); return exitCode; }