/** * Initializes the application. * * Called upon startup and initializes the program by creating the main window. * * @return TRUE indicates a successful intialization */ bool GcbApp::OnInit() { bool success = true; closeApp = false; try { SetWorkingDirectory(); //wxString userDataPath = wxStandardPaths::Get().GetUserDataDir(); CheckDirectories(); // Reassign stderr and stdout errStream = freopen( "log\\stderr.txt", "w", stderr ); outStream = freopen( "log\\stdout.txt", "w", stdout ); InitializeGameFrame(); gameFrame->Show(true); SetTopWindow(gameFrame); eventLoop = new wxEventLoop(); wxEventLoop::SetActive(eventLoop); } catch (...) { success = false; } return success; }
static void MainRig_Startup(const StartupConfig& cfg, VariantFunctions& serv) { std::string appNameString = cfg._applicationName; std::string logCfgString = cfg._logConfigFile; serv.Add<std::string()>( Fn_GetAppName, [appNameString](){ return appNameString; }); serv.Add<std::string()>( Fn_LogCfg, [logCfgString](){ return logCfgString; }); srand(std::random_device().operator()()); auto guidGen = std::make_shared<std::mt19937_64>(std::random_device().operator()()); serv.Add<uint64()>( Fn_GuidGen, [guidGen](){ return (*guidGen)(); }); // // We need to initialize logging output. // The "int" directory stands for "intermediate." We cache processed // models and textures in this directory // But it's also a convenient place for log files (since it's excluded from // git and it contains only temporary data). // Note that we overwrite the log file every time, destroying previous data. // CreateDirectoryRecursive("int"); if (cfg._setWorkingDir) SetWorkingDirectory(); }
bool WorkspaceManager::SelectCurrentWorkspace(const char* DefaultWorkspacePath) { char WorkspacePath[MAX_PATH] = {0}; if (DefaultWorkspacePath == nullptr) { BROWSEINFO WorkspaceInfo = {0}; WorkspaceInfo.hwndOwner = BGSEEUI->GetMainWindow(); WorkspaceInfo.iImage = 0; WorkspaceInfo.pszDisplayName = WorkspacePath; WorkspaceInfo.lpszTitle = "Select a valid workspace inside the root game directory"; WorkspaceInfo.ulFlags = BIF_NEWDIALOGSTYLE|BIF_RETURNONLYFSDIRS; WorkspaceInfo.pidlRoot = nullptr; WorkspaceInfo.lpfn = nullptr; WorkspaceInfo.lParam = NULL; PIDLIST_ABSOLUTE ReturnPath = SHBrowseForFolder(&WorkspaceInfo); if (ReturnPath) { if (!SHGetPathFromIDList(ReturnPath, WorkspacePath)) { BGSEEUI->MsgBoxE("Couldn't determine workspace folder path."); return false; } } else { return false; } } else sprintf_s(WorkspacePath, MAX_PATH, "%s", DefaultWorkspacePath); strcat_s(WorkspacePath, MAX_PATH, "\\"); if (strstr(WorkspacePath, DefaultDirectory.c_str()) == WorkspacePath) { if (_stricmp(CurrentDirectory.c_str(), WorkspacePath)) { Operator->ResetCurrentWorkspace(); Operator->ReloadPlugins(std::string(CurrentDirectory + "Data\\").c_str(), true, false); SetWorkingDirectory(WorkspacePath); CreateDefaultDirectories(WorkspacePath); Operator->ReloadPlugins("Data\\", false, true); BGSEEUI->MsgBoxI("Current workspace set to '%s'.", WorkspacePath); return true; } return false; } else { BGSEEUI->MsgBoxW("The new workspace must be inside the root game directory."); return false; } }
/** * create log file */ void createOsLogFile(const char *dir, const char *fileName) { //open directory etc SetWorkingDirectory(dir); const char loginput[] = { "[0] log file created\n" }; int length = strlen(loginput); // create the log file //File_t logfile = OpenF(fileName, O_CREAT | O_READ | O_WRITE); // write variables on file and close it //Write(logfile, loginput, length); //Close(logfile); }
/** * create environment file */ void createOsEnvironmentFile(const char *dir, const char *fileName) { //open directory etc SetWorkingDirectory(dir); // define first variables const char envvar[] = { "HOSTNAME=MeetiX_OS\nVERSION=0.7.1\nSYSTEM_LEVEL=basic\nPATH=/cmd/:/app/:/sys/eva/server/\nTHEME=multi\n" }; int length = strlen(envvar); // create the environment file File_t env = OpenF(fileName, O_CREAT | O_READ | O_WRITE); // write variables on file and close it Write(env, envvar, length); Close(env); }
status_t SVNSourceControl::CreateRepository(const char *path) { // The SourceControl class runs under the DSCM idea of the local directory // being a repository. Seeing how SVN doesn't allow for this, we create a // repository elsewhere on the hard drive, check it out to the path we were // given, and add the files to the repository. Checking in is not part of // this call, however. DPath workingDir(path); DPath repoPath(sRepoPath); repoPath << workingDir.GetFileName(); BDirectory dir(sRepoPath.String()); if (dir.InitCheck() != B_OK) create_directory(sRepoPath.String(), 0777); BString command("svnadmin create "); command << "'" << repoPath.GetFullPath() << "'"; BString out; RunCommand(command, out); BString repoURL = "file://"; repoURL << repoPath.GetFullPath(); SetURL(repoURL.String()); SetWorkingDirectory(path); CloneRepository(repoURL.String(), path); BPath svnpath(path); svnpath.Append(".svn"); if (!BEntry(svnpath.Path()).Exists()) return B_ERROR; command = ""; command << "cd '" << path << "'; " << "svn add --non-interactive *"; RunCommand(command, out); return B_OK; }
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { InitializeLib(ImageHandle, SystemTable); CallConstructors(); EFI_STATUS Status; const char16_t* searchdir = u"\\EFI\\ChaiOS\\"; if (Status = SetWorkingDirectory(searchdir)) printf(u"Error setting working directory: %s\r\n", getError(Status)); CHAIOS_BOOT_FILES* bootfile = nullptr; while (bootfile = iterateBootFiles(bootfile)) { if (bootfile->loadLocation != nullptr) continue; //Support in-memory images EFI_FILE* file = OpenFile(bootfile->fileName, "r"); if (!file) { printf(u"Error: could not open %s: %s\r\n", bootfile->fileName, getError(getErrno())); } UINT64 fileSize = GetFileSize(file); VOID* bootfilebuf = kmalloc(fileSize+1); UINTN read = ReadFile(bootfilebuf, 1, fileSize, file); if (read < fileSize) printf(u"Read %d bytes, failed\r\n", read); else printf(u"Successfully read %d bytes\r\n", read); //Boot file is now loaded into memory CloseFile(file); bootfile->loadLocation = bootfilebuf; bootfile->fileSize = fileSize; if (bootfile->bootType == CHAIOS_BOOT_CONFIGURATION) { //We need to parse this now. INI format ((char*)bootfilebuf)[fileSize] = '\0'; ini_parse_string((const char*)bootfilebuf, &bootini_handler, nullptr); } } //size_t value = GetIntegerInput(u"Enter scrolling lines configuration: "); //set_scrolllines(value); UINT32 AutoMode = IterateGraphicsMode(&match_config_resoultion); EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* info; UINTN SizeOfInfo; if (AutoMode == UINT32_MAX) { if (!EFI_ERROR(GetGraphicsModeInfo(AutoMode, &info, &SizeOfInfo))) { IterateGraphicsMode(&print_graphics_mode); size_t value = GetIntegerInput(u"Enter boot graphics mode: "); SetGraphicsMode(value); AutoMode = value; } } else { SetGraphicsMode(AutoMode); } if (!EFI_ERROR(GetGraphicsModeInfo(AutoMode, &info, &SizeOfInfo))) { printf(u"Graphics mode %d: %dx%d\r\n", AutoMode, info->HorizontalResolution, info->VerticalResolution); } puts(u"ChaiOS 0.09 UEFI Loader\r\n"); int majorver = SystemTable->Hdr.Revision / (1 << 16); int minorver = SystemTable->Hdr.Revision % (1 << 16); printf(u"Firmware Vendor: %s, version: %d (UEFI:%d.%d)\r\n", SystemTable->FirmwareVendor, SystemTable->FirmwareRevision, majorver, minorver); //Read ACPI configuration tables //startup_acpi(SystemTable); //startup_multiprocessor(); const size_t EARLY_PAGE_STACK_SIZE = 1024*1024; EFI_PHYSICAL_ADDRESS earlyPhypageStack = 0; if (EFI_ERROR(SystemTable->BootServices->AllocatePages(AllocateAnyPages, EfiLoaderData, EARLY_PAGE_STACK_SIZE / EFI_PAGE_SIZE, &earlyPhypageStack))) { puts(u"Could not allocate page stack\r\n"); return EFI_OUT_OF_RESOURCES; } SystemTable->BootServices->SetWatchdogTimer(0, 0, 0, nullptr); PrepareExitBootServices(); EfiMemoryMap map; map.MemMapSize = map.MapKey = map.DescriptorSize = map.DescriptorVersion = 0; SystemTable->BootServices->GetMemoryMap(&map.MemMapSize, nullptr, &map.MapKey, &map.DescriptorSize, &map.DescriptorVersion); //Give a nice bit of room to spare (memory map can change) map.MemMapSize += 16 * map.DescriptorSize; map.memmap = (EFI_MEMORY_DESCRIPTOR*)kmalloc(map.MemMapSize); //Allocate a nice buffer SystemTable->BootServices->GetMemoryMap(&map.MemMapSize, map.memmap, &map.MapKey, &map.DescriptorSize, &map.DescriptorVersion); printf(u"EFI Memory Map: Descriptor size %d\n", map.DescriptorSize); #if 0 //Dump the UEFI memory map to a file for testing EFI_FILE* file = OpenFile(u"efimap.dat", "w"); if (!file) { printf(u"Error: could not open %s: %s\r\n", u"efimap.dat", getError(getErrno())); } WriteFile(map.memmap, 1, map.MemMapSize, file); CloseFile(file); #endif if (EFI_ERROR(Status = SystemTable->BootServices->ExitBootServices(ImageHandle, map.MapKey))) { printf(u"Failed to exit boot services: %s\r\n", getError(Status)); UINTN index; SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, &index); return EFI_SUCCESS; } //We need to take control of the hardware now. Setup basic memory management setLiballocAllocator(nullptr, nullptr); InitializePmmngr(map, (void*)earlyPhypageStack, EARLY_PAGE_STACK_SIZE); puts(u"Physical memory manager intialized\n"); arch_initialize_paging(); puts(u"Paging initialized\n"); setLiballocAllocator(&arch_allocate_pages, &arch_free_pages); //Now load the OS! bootfile = nullptr; kimage_entry kentry = nullptr; KLOAD_HANDLE kernel = NULL; while (bootfile = iterateBootFiles(bootfile)) { printf(u"Boot file: %s @ %x, length %d, type %d\n", bootfile->fileName, bootfile->loadLocation, bootfile->fileSize, bootfile->bootType); if (!bootfile->loadLocation) continue; if (bootfile->bootType == CHAIOS_DLL) { KLOAD_HANDLE dll = LoadImage(bootfile->loadLocation, bootfile->fileName); if (GetProcAddress(dll, "memcpy")) { set_memcpy((memcpy_proc)GetProcAddress(dll, "memcpy")); } } else if (bootfile->bootType == CHAIOS_KERNEL) { kernel = LoadImage(bootfile->loadLocation, bootfile->fileName); kentry = GetEntryPoint(kernel); } } size_t kstacksize = GetStackSize(kernel); if (!paging_map(stackaddr, PADDR_T_MAX, kstacksize, PAGE_ATTRIBUTE_WRITABLE)) { puts(u"Error: could not allocate kernel stack\n"); while (1); } KERNEL_BOOT_INFO bootinfo; fill_pmmngr_info(bootinfo.pmmngr_info); fill_arch_paging_info(bootinfo.paging_info); fill_modloader_info(bootinfo.modloader_info); get_framebuffer_info(bootinfo.fbinfo); populate_kterm_info(bootinfo.kterm_status); bootinfo.efi_system_table = SystemTable; bootinfo.memory_map = ↦ bootinfo.loaded_files = &bootfiles; bootinfo.boottype = CHAIOS_BOOT_TYPE_UEFI; bootinfo.printf_proc = &printf; bootinfo.puts_proc = &puts; printf(u"Success: Kernel entry point at %x, stack at %x, length %x\n", kentry, stackaddr, kstacksize); call_kernel(&bootinfo, kentry, stackaddr, kstacksize); puts(u"Kernel returned"); while (1); }
FindWindow::FindWindow(BString workingDir) : DWindow(BRect(100,100,600,500), B_TRANSLATE("Find in project"), B_TITLED_WINDOW, B_CLOSE_ON_ESCAPE), fIsRegEx(false), fIgnoreCase(true), fMatchWord(false), fThreadID(-1), fThreadMode(0), fThreadQuitFlag(0), fFileList(20, true), fWorkingDir(""), fProject(NULL) { SetSizeLimits(650, 30000, 400, 30000); MakeCenteredOnShow(true); fMenuBar = new BMenuBar("menubar"); fFindButton = new BButton("findbutton", B_TRANSLATE("Replace all"), new BMessage(M_FIND)); fFindButton->SetLabel(B_TRANSLATE("Find")); fFindButton->SetEnabled(false); fFindBox = new DTextView("findbox"); fFindBox->SetFlags(fFindBox->Flags() | B_NAVIGABLE_JUMP); BScrollView *findBoxScroll = fFindBox->MakeScrollView("findscroll", true, true); fReplaceBox = new DTextView("replacebox"); fReplaceBox->SetFlags(fFindBox->Flags() | B_NAVIGABLE_JUMP); BScrollView *replaceBoxScroll = fReplaceBox->MakeScrollView("replacescroll", true, true); BGroupLayout* hGroup = new BGroupLayout(B_HORIZONTAL,0); BView* hView = new BView("hview",0,hGroup); fReplaceButton = new BButton("replacebutton", B_TRANSLATE("Replace"), new BMessage(M_REPLACE)); fReplaceButton->SetEnabled(false); //hGroup->AddView(fReplaceButton); // hidden until we decide we need an individual replace in a multi // file dialog box (doubtful - could click on file and do it from // within pe) fReplaceAllButton = new BButton("replaceallbutton", B_TRANSLATE("Replace all"), new BMessage(M_REPLACE_ALL)); fReplaceAllButton->SetEnabled(false); hGroup->AddView(fReplaceAllButton); BStringView *resultLabel = new BStringView("resultlabel", B_TRANSLATE("Results:")); fResultList = new DListView("resultlist", B_MULTIPLE_SELECTION_LIST); BScrollView* resultsScroll = fResultList->MakeScrollView("resultscroll", true, true); resultsScroll->SetExplicitMinSize(BSize(650,150)); fResultList->SetInvocationMessage(new BMessage(M_SHOW_RESULT)); BLayoutBuilder::Group<>(this, B_VERTICAL) .Add(fMenuBar) .Add(findBoxScroll) .Add(fFindButton) .Add(replaceBoxScroll) .Add(hView) .Add(resultLabel) .Add(resultsScroll) .End(); BMenu *menu = new BMenu(B_TRANSLATE("Search")); menu->AddItem(new BMenuItem(B_TRANSLATE("Find"), new BMessage(M_FIND), 'F', B_COMMAND_KEY)); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Replace"), new BMessage(M_REPLACE), 'R', B_COMMAND_KEY)); menu->AddItem(new BMenuItem(B_TRANSLATE("Replace all"), new BMessage(M_REPLACE_ALL), 'R', B_COMMAND_KEY | B_SHIFT_KEY)); fMenuBar->AddItem(menu); menu = new BMenu(B_TRANSLATE("Options")); menu->AddItem(new BMenuItem(B_TRANSLATE("Regular expression"), new BMessage(M_TOGGLE_REGEX))); menu->AddItem(new BMenuItem(B_TRANSLATE("Ignore case"), new BMessage(M_TOGGLE_CASE_INSENSITIVE))); menu->AddItem(new BMenuItem(B_TRANSLATE("Match whole word"), new BMessage(M_TOGGLE_MATCH_WORD))); fMenuBar->AddItem(menu); BMenuItem *item = fMenuBar->FindItem(B_TRANSLATE("Ignore case")); if (fIgnoreCase) item->SetMarked(true); menu = new BMenu(B_TRANSLATE("Project")); menu->SetRadioMode(true); gProjectList->Lock(); for (int32 i = 0; i < gProjectList->CountItems(); i++) { Project *proj = gProjectList->ItemAt(i); BMessage *msg = new BMessage(M_SET_PROJECT); msg->AddPointer("project", proj); BMenuItem *projItem = new BMenuItem(proj->GetName(), msg); menu->AddItem(projItem); if (gCurrentProject == proj) { projItem->SetMarked(true); fProject = proj; } } gProjectList->Unlock(); fMenuBar->AddItem(menu); SetProject(fProject); EnableReplace(false); SetWorkingDirectory(workingDir); // The search terms box will tell us whenever it has been changed at every keypress fFindBox->SetMessage(new BMessage(M_FIND_CHANGED)); fFindBox->SetTarget(this); fFindBox->SetChangeNotifications(true); fFindBox->MakeFocus(true); fReplaceBox->SetMessage(new BMessage(M_REPLACE_CHANGED)); fReplaceBox->SetTarget(this); fReplaceBox->SetChangeNotifications(true); }
int main( int argc, char** argv ) { QApplication app( argc, argv ); QTranslator qtr( 0 ); QTranslator qtr2( 0 ); // Set our working directory #ifdef _WIN32 QString datadir = QString::fromLocal8Bit(qgetenv("APPDATA").constData()); QDir dir(datadir); dir.mkdir("Image Splitter"); datadir = MakePath(datadir, "Image Splitter"); gDataDir = datadir; #ifdef _DEBUG WString wdatadir(datadir); qDebug("Data directory: %ls", wdatadir.getBuffer()); #endif gAppDir = QDir::toNativeSeparators(app.applicationDirPath()); // Set our working directory QDir::setCurrent(datadir); #endif // Load language file QString langfile; #ifndef _WIN32 langfile = "isplitter.lng"; // Set our working directory SetWorkingDirectory(argv[0]); gAppDir = QDir::currentPath(); #else langfile = MakePath(gDataDir, "isplitter.lng"); #endif QFile lang(langfile); QString lfile; QString ldir = MakePath(gAppDir, "translations"); QDir ld(ldir); // Try to find directory containing translation files if (!ld.exists()) { ld.cdUp(); // If there is no "translations" sub-directory, check the directory containing the executable if (ld.exists("isplitter_en.qm")) { ldir = gAppDir; } else { // ... then try its parent directory, for example if we are running from Visual Studio ld.cdUp(); if (ld.exists("isplitter_en.qm")) { ldir = QDir::toNativeSeparators(ld.absolutePath()); } } } if (!lang.exists()) { NoTranslation: lfile = QFileDialog::getOpenFileName(NULL, app.translate("main", "Open translation file..."), ldir, "isplitter_*.qm"); // Save selected language's translator filename if (!lfile.isEmpty() && lang.open(QIODevice::WriteOnly) ) { QByteArray clang = lfile.toUtf8(); lang.write(clang); lang.close(); } } // (Re-)load translator filename if ( lang.open(QIODevice::ReadOnly) ) { // file opened successfully QByteArray plang = lang.readLine(); lfile = QString::fromUtf8(plang); lang.close(); } // Install translator ;) if (!lfile.isEmpty() && QFile::exists(lfile) && qtr.load(lfile)) app.installTranslator(&qtr); else goto NoTranslation; // Qt's own translator file QFileInfo qfi(lfile); QString qt_lang = QString::null; QString qtdir = QString::fromLocal8Bit(qgetenv("QTDIR").constData()); langfile = qfi.fileName().replace(QRegExp("isplitter"), "qt"); if (qtdir != QString::null) { QString tr_dir = MakePath(qtdir, "translations"); qt_lang = MakePath(tr_dir, langfile); if (!QFile::exists(qt_lang)) qt_lang = QString::null; } // Try using same directory as Image Splitter's translations if (qt_lang == QString::null) { qt_lang = MakePath(qfi.absolutePath(), langfile); } if (QFile::exists(qt_lang) && qtr2.load(qt_lang)) { app.installTranslator( &qtr2 ); } ImageSplitter * window = new ImageSplitter(NULL); Q_CHECK_PTR(window); window->show(); if (app.arguments().count() > 1) window->Load(app.arguments().at(1)); return app.exec(); }