bool MapBG::Load(const char* fp) { if (!FileExists(fp)) { LOG(NFormat("MapBG: File not exists, \"%s\"", fp)); return false; } if (!LoadFromXMLFile(_levels, fp)) { LOG("MapBG: Error while loading map from XML-file!"); return false; } _mapDir = AppendFileName(GetFileDirectory(fp), GetFileTitle(fp)); _currLevel = _levels.GetCount() > 0 ? 0 : -1; if (_currLevel < 0) { LOG("MapBG: No zoom levels found in map!"); return false; } _recalc = true; return true; }
void MapEditor::OnLevelMapCalc(Level& level, int number) { if (level.GetMapBG().IsEmpty()) { Exclamation(NFormat(t_("Please, select the image for level: %s"), level.GetName())); return; } String fp = AppendFileName( AppendFileName( GetFileDirectory(GetExeFilePath()), "Maps"), level.GetMapBG()); if (!FileExists(fp)) { Exclamation(NFormat(t_("Image file not exist: %s"), fp)); return; } String name = level.GetName(); double zx = level.GetZoomDX(); Size pz = level.GetPageSize(); Size sz = level.GetCellSize(); FileIn in(fp); One<StreamRaster> r = StreamRaster::OpenAny(in); if (!r) { Exclamation(NFormat(t_("Error while loading image file: %s"), fp)); return; } Image img = r->GetImage(); Calculate(sz.cx, sz.cy, pz.cx, pz.cy, zx, NFormat("%s-%d", _map.GetName(), number + 1), img); }
void defList::Save() { if (path.IsEmpty()) { path = ConfigFile(name + ".list") ; } else if ( name != GetFileTitle(path)) { path = GetFileDirectory(path) + name + ".list" ; } String s ; s << "name=" << name << "\r\n" << "fields=" ; for (int i = 0; i < fields.GetCount(); i++) s << fields[i] << "," ; s << "\r\n" ; for (int i = 0; i < data.GetCount(); i++) { s << "data_" << i << "=" ; Vector<String>&line = data[i] ; for (int j = 0; j < line.GetCount(); j++) { if (j > 0) s << "," ; s << "\"" << line[j] << "\"" ; } s << "\r\n" ; } for (int i = 0; i < errors.GetCount(); i++) s << "error_" << i << "=" << errors[i] << "\r\n" ; SaveFile(path, s) ; }
void MapEditor::OnLevelMapList(VectorMapEx<String, Value>& mapList) { Vector<String> files = GetDirectoryFiles( AppendFileName( GetFileDirectory(GetExeFilePath()), "Maps")); Sort(files); for (int i = 0; i < files.GetCount(); ++i) mapList.Add(files[i], files[i]); }
//============================================================================================== // As the one and only main window, determine if we are in production or not. // Eventually fix call to replace GUI_MAIN with URP_MAIN which includes __FILE__ macro void UrpTopWindow::Init(const char *pmainFilePath) { mainFilePath = pmainFilePath; // If we are nested in the Program Files directory, we must be a proper user install and we need to use the users's configuration files if (exeFilePath.Find("Program Files") >= 0) { envCode = ENV_PROD; configFileFolder = GetHomeDirectory(); } else { envCode = ENV_DEV; // We are probably in the dev env and running from the ide, and so we pull from our current directory configFileFolder = GetFileDirectory(mainFilePath); } }
String FollowCygwinSymlink(const String& file) { for(String fn = file;;) { if(fn.IsEmpty()) return fn; FileIn fi(fn); if(!fi.IsOpen()) return fn; char buffer[10]; if(!fi.GetAll(buffer, 10) || memcmp(buffer, "!<symlink>", 10)) return fn; fn = NormalizePath(LoadStream(fi), GetFileDirectory(fn)); } }
bool FindFile::Search(const char *name) { pattern = GetFileName(name); path = NormalizePath(GetFileDirectory(name)); Close(); if(w) handle = UnicodeWin32().FindFirstFileW(ToSystemCharsetW(name), w); else handle = FindFirstFile(ToSystemCharset(name), a); if(handle == INVALID_HANDLE_VALUE) return false; if(!PatternMatch(pattern, GetName())) return Next(); return true; }
void Ide::CreateMakefile() { const Workspace& wspc = IdeWorkspace(); if(wspc.GetCount() == 0) { PutConsole("Project is empty!"); return; } FileSel mfout; mfout.AllFilesType(); mfout <<= AppendFileName(GetFileDirectory(PackagePath(wspc[0])), "Makefile"); if(!mfout.ExecuteSaveAs("Save makefile as")) return; SaveMakeFile(~mfout, true); }
void MapEditor::OnSaveMap() { CalculateAllPrompt(); if (!StoreAsXMLFile(_map, _map.GetName(), AppendFileName( AppendFileName(GetFileDirectory(GetExeFilePath()), "Mipmaps"), _map.GetName() + ".map" ))) { Exclamation(t_("Error while saving map to file!")); } UpdateEditorCtrls(); }
void FormEdit::TestLayout() { String preview = (_File.IsEmpty()) ? ConfigFile("FormEditor.view") : GetFileDirectory(_File) + "\\" + "FormEditor.view"; _View.SaveAll(preview, false); Form form; form.Load(preview); form.Layout(_View.GetCurrentLayout()->Get("Form.Name"), _View.GetFont()); form.ExecuteForm(); DeleteFile(preview); }
void CCedtApp::OnSearchFindInFiles() { // static dialog box to remember last settings... static CFindInFilesDialog dlg; CMainFrame * pFrame = (CMainFrame *)AfxGetMainWnd(); ASSERT( pFrame ); if( ! pFrame->CanUseOutputWindow() ) { AfxMessageBox(IDS_ERR_OUTPUT_WINDOW_OCCUPIED, MB_OK | MB_ICONSTOP); return; } CCedtView * pView = (CCedtView *)pFrame->MDIGetActiveView(); CCedtDoc * pDoc = (pView) ? (CCedtDoc *)pView->GetDocument() : NULL; if( pDoc && pView ) { dlg.m_szFindString = pView->GetCurrentWord(); if( pView->IsSelected() && ! pView->GetSelectedLineCount() ) dlg.m_szFindString = pView->GetSelectedString(); if( ! dlg.m_szFolder.GetLength() ) { CString szPathName = pDoc->GetPathName(); if( szPathName.GetLength() ) dlg.m_szFolder = GetFileDirectory( szPathName ); } } else { if( ! dlg.m_szFolder.GetLength() ) { TCHAR szTemp[MAX_PATH]; GetCurrentDirectory(MAX_PATH, szTemp); dlg.m_szFolder = szTemp; } } if( dlg.DoModal() != IDOK ) return; CString szFindString = dlg.m_szFindString; CString szFileType = dlg.m_szFileType; CString szFolder = dlg.m_szFolder; BOOL bLookSubfolders = dlg.m_bLookSubfolders; UINT nOptions = COMPOSE_SEARCH_OPTION( dlg.m_bWholeWord, dlg.m_bMatchCase, dlg.m_bRegularExpression); CRegExp clsTestRegExp; // compile regular expression for test if( HAS_REG_EXP(nOptions) && ! clsTestRegExp.RegComp(szFindString) ) { CString szMessage; szMessage.Format(IDS_ERR_REG_COMP_FAILED, szFindString); AfxMessageBox(szMessage); return; // test failed } DoFindInFiles(szFindString, szFileType, szFolder, bLookSubfolders, nOptions); }
bool FindFile::Search(const char *fn) { Close(); path = NormalizePath(GetFileDirectory(fn)); statis = false; file = false; if(HasWildcards(fn)) { pattern = GetFileName(fn); dir = opendir(ToSystemCharset(path)); return Next(); } else { name = GetFileName(fn); if(stat(ToSystemCharset(fn), &statf)) return false; statis = true; file = true; return true; } }
void defMsg::Save() { if (path.IsEmpty()) { path = ConfigFile(name + ".msg") ; } else if ( name != GetFileTitle(path)) { path = GetFileDirectory(path) + name + ".msg" ; } String f ; f << "from=" << from << "\r\n" << "subject="<< subject << "\r\n" ; Vector<String> lines = String2VectorString(qtfBody) ; for (int i = 0; i < lines.GetCount(); i++) f << "body" << i << "=" << lines[i] << "\r\n" ; SaveFile(path, f) ; }
void MapEditor::OnLoadMap() { WithMapLoadLayout<TopWindow> dlg; CtrlLayoutOKCancel(dlg, t_("Load Map...")); String dir = AppendFileName( GetFileDirectory(GetExeFilePath()), "Mipmaps"); Vector<String> files = GetDirectoryFiles(dir, "*.map"); Sort(files); if (files.GetCount() <= 0) { Exclamation(t_("No any file to load!")); return; } for (int i = 0; i < files.GetCount(); ++i) dlg.MapList.Add(files[i], files[i]); dlg.MapList.SetIndex(0); if (dlg.Execute() != IDOK) return; String fp = AppendFileName(dir, (~dlg.MapList).ToString()); if (!FileExists(fp)) { Exclamation(NFormat(t_("File not found: %s"), fp)); return; } if (!LoadFromXMLFile(_map, fp)) { Exclamation(NFormat(t_("Error while loading map from file: %s"), fp)); return; } UpdateLevelList(); UpdateEditorCtrls(); }
One<Host> MakeBuild::CreateHost(bool sync_files) { SetupDefaultMethod(); VectorMap<String, String> bm = GetMethodVars(method); One<Host> outhost; { One<LocalHost> host = new LocalHost; VectorMap<String, String> env(Environment(), 1); host->exedirs = SplitDirs(bm.Get("PATH", "") + ';' + env.Get("PATH", "")); env.GetAdd("PATH") = Join(host->exedirs, ";"); env.GetAdd("UPP_MAIN__") = GetFileDirectory(PackagePath(GetMain())); env.GetAdd("UPP_ASSEMBLY__") = GetVar("UPP"); for(int i = 0; i < env.GetCount(); i++) { LDUMP(env.GetKey(i)); LDUMP(env[i]); host->environment << env.GetKey(i) << '=' << env[i] << '\0'; } host->environment.Cat(0); host->cmdout = &cmdout; outhost = -host; } return outhost; }
TString GetFileDirectory(const TChar* path) { return GetFileDirectory(path, _tcslen(path)); }
TString GetApplicationDirectory() { return GetFileDirectory(GetApplicationPath()); }
void WorkspaceWork::OpenPackageFolder() { ShellOpenFolder(GetFileDirectory(GetActivePackagePath())); }
NAMESPACE_UPP String FileTabs::GetFileGroup(const String &file) { return GetFileDirectory(file); }
dictionary* INI::LoadIniFile(HINSTANCE hInstance, LPSTR inifile) { dictionary* ini = NULL; // First attempt to load INI from exe HRSRC hi = FindResource(hInstance, MAKEINTRESOURCE(1), RT_INI_FILE); if(hi) { HGLOBAL hg = LoadResource(hInstance, hi); PBYTE pb = (PBYTE) LockResource(hg); DWORD* pd = (DWORD*) pb; if(*pd == INI_RES_MAGIC) { ini = iniparser_load((char *) &pb[RES_MAGIC_SIZE], true); if(!ini) { Log::Warning("Could not load embedded INI file"); } } } // Check if we have already loaded an embedded INI file - if so // then we only need to load and merge the INI file (if present) if(ini && iniparser_getboolean(ini, ALLOW_INI_OVERRIDE, 1)) { dictionary* ini2 = iniparser_load(inifile); if(ini2) { for(int i = 0; i < ini2->n; i++) { char* key = ini2->key[i]; char* value = ini2->val[i]; iniparser_setstr(ini, key, value); } iniparser_freedict(ini2); } } else if(!ini) { ini = iniparser_load(inifile); if(ini == NULL) { Log::Error("Could not load INI file: %s", inifile); return NULL; } } // Expand environment variables ExpandVariables(ini); // Now check if we have an external file to load char* iniFileLocation = iniparser_getstr(ini, INI_FILE_LOCATION); if(iniFileLocation) { Log::Info("Loading INI keys from file location: %s", iniFileLocation); dictionary* ini3 = iniparser_load(iniFileLocation); if(ini3) { for(int i = 0; i < ini3->n; i++) { char* key = ini3->key[i]; char* value = ini3->val[i]; iniparser_setstr(ini, key, value); } iniparser_freedict(ini3); } else { Log::Warning("Could not load INI keys from file: %s", iniFileLocation); } } // Attempt to parse registry location to include keys if present ParseRegistryKeys(ini); iniparser_setstr(ini, MODULE_INI, inifile); // Add module name to ini TCHAR filename[MAX_PATH], filedir[MAX_PATH]; GetModuleFileName(hInstance, filename, MAX_PATH); iniparser_setstr(ini, MODULE_NAME, filename); // strip off filename to get module directory GetFileDirectory(filename, filedir); iniparser_setstr(ini, MODULE_DIR, filedir); // stip off filename to get ini directory GetFileDirectory(inifile, filedir); iniparser_setstr(ini, INI_DIR, filedir); // Log init Log::Init(hInstance, iniparser_getstr(ini, LOG_FILE), iniparser_getstr(ini, LOG_LEVEL), ini); Log::Info("Module Name: %s", filename); Log::Info("Module INI: %s", inifile); Log::Info("Module Dir: %s", filedir); Log::Info("INI Dir: %s", filedir); // Store a reference to be used by JNI functions g_ini = ini; return ini; }
void FormEdit::UpdateChildCount(int count) { for (int i = 0; i < _Ctrls.GetCount(); ++i) _CtrlContainer.RemoveChild(&_Ctrls[i]); _Ctrls.Clear(); _ItemList.Clear(); _Temporaries.Clear(); if (!_View.IsLayout()) { UpdateItemList(); return; } // if (_ViewMode == VIEW_MODE_WIREFRAME) // return; for (int i = 0; i < count; ++i) { if (!_View.GetObject(i)) continue; String type = (*_View.GetObjects())[i].Get("Type"); Font font = _View.GetFont(); int h = _View.ZoomY((*_View.GetObjects())[i].GetNumber("Font.Height")); if (h != 0) font.Height(h); if (font.GetHeight() == 0) font.Height(StdFont().GetHeight()); _ItemList.AddRow(type, (*_View.GetObjects())[i].Get("Variable")); if ((*_View.GetObjects())[i].GetBool("OutlineDraw", false) && _ViewMode != VIEW_MODE_AS_IS) { if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( _Ctrls.Create<StaticRect>() ); } else if (type == "Button") { Button* b = &_Ctrls.Create<Button>(); b->SetFont(font); if (_ViewMode == VIEW_MODE_AS_IS) b->SetLabel((*_View.GetObjects())[i].Get("Label")); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "DropDate") { DropDate *b = &_Ctrls.Create<DropDate>(); b->SetFont(font); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "GridCtrl") { GridCtrl *b = &_Ctrls.Create<GridCtrl>(); // b->SetFont(font); TODO #ifdef PLATFORM_WIN32 b->Chameleon(); #endif String src = (*_View.GetObjects())[i].Get("Grid.Columns"); ReplaceString(src, ";", "\r\n"); StringStream s; s.Open(src); IniFile f; f.Load(s); Vector<String> names = f.EnumNames("Columns"); for (int j = 0; j < names.GetCount(); ++j) { int n = ScanInt(names[j]); Vector<String> values = f.GetArray("Columns", names[j]); if (values.GetCount() != 3) continue; if (values[1] == "Left") b->AddColumn(values[0]).HeaderAlignCenterLeft(); else if (values[1] == "Right") b->AddColumn(values[0]).HeaderAlignCenterRight(); else b->AddColumn(values[0]).HeaderAlignCenter(); } if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "EditField") { EditField *b = &_Ctrls.Create<EditField>(); b->SetFont(font); if (_ViewMode == VIEW_MODE_AS_IS) b->SetText((*_View.GetObjects())[i].Get("DefaultData")); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "EditInt") { EditInt *b = &_Ctrls.Create<EditInt>(); b->SetFont(font); if (_ViewMode == VIEW_MODE_AS_IS) b->SetText((*_View.GetObjects())[i].Get("DefaultData")); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "ProgressBar") { ProgressIndicator *b = &_Ctrls.Create<ProgressIndicator>(); b->Set(0, 100); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "TabCtrl") { TabCtrl* e = &_Ctrls.Create<TabCtrl>(); TabCtrl::Style& style = e->StyleDefault().Write(); style.font = font; style.tabheight = font.GetHeight() + VertLayoutZoom(10); e->SetStyle(style); String src = (*_View.GetObjects())[i].Get("Tab.Content"); ReplaceString(src, ";", "\r\n"); StringStream s; s.Open(src); IniFile f; f.Load(s); Vector<String> names = f.EnumNames("Tabs"); VectorMap<int, Vector<String> > cache; int tabCount = 0; for (int j = 0; j < names.GetCount(); ++j) { int n = ScanInt(names[j]); if (AsString(n) != names[j]) continue; Vector<String> values = f.GetArray("Tabs", names[j]); if (values.GetCount() != 3) continue; Container *cont = &_Temporaries.Create<Container>(); Form *f = &_Temporaries.Create<Form>(); if (values[0] != t_("Current form")) { if (!f->Load(GetFileDirectory(_File) + "\\" + values[0])) continue; } else { int lay = _View.HasLayout(values[1]); if (lay < 0) continue; f->GetLayouts().Add() <<= _View.GetLayouts()[lay]; } if (!f->Layout(values[1], font)) continue; cont->Set(*f, f->GetSize()); cont->SizePos(); e->Add(*cont, values[2]); tabCount++; } int activeTab = -1; if (tabCount) { activeTab = (*_View.GetObjects())[i].GetNumber("Tab.Active", 0, 0); if (activeTab >= tabCount) { activeTab = tabCount - 1; e->Set(activeTab); } e->Set(activeTab); } (*_View.GetObjects())[i].SetNumber("Tab.Active", activeTab); (*_View.GetObjects())[i].SetNumber("Tab.Count", tabCount); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( e->NoWantFocus() ); } else if (type == "Form") { Form f; String path = (*_View.GetObjects())[i].Get("Form.Path"); (*_View.GetObjects())[i].Get("Form.PathType") == "Relative" ? f.Load(::GetFileDirectory(_File) + "\\" + path) : f.Load(path); f.Layout((*_View.GetObjects())[i].Get("Form.Layout"), font); ImageDraw w(f.GetSize()); f.DrawCtrl(w); ImageBuffer buf(w); StaticImage *s = &_Ctrls.Create<StaticImage>(); s->SetImage(buf); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.AddChild( s ); } else { Label *b = &_Ctrls.Create<Label>(); b->SetFont(font); Color fontColor = DefaultInk(); LoadFromString(fontColor, Decode64((*_View.GetObjects())[i].Get("Font.Color", StoreAsString(fontColor)))); b->SetInk(fontColor); String align = (*_View.GetObjects())[i].Get("Text.Align"); if (align == "Center") b->SetAlign(ALIGN_CENTER); if (align == "Right") b->SetAlign(ALIGN_RIGHT); if (align == "Left") b->SetAlign(ALIGN_LEFT); if (_ViewMode == VIEW_MODE_AS_IS) b->SetLabel((*_View.GetObjects())[i].Get("Label")); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } String frame = (*_View.GetObjects())[i].Get("Frame"); Ctrl* c = NULL; if (_Ctrls.GetCount()) c = &_Ctrls[_Ctrls.GetCount() - 1]; if (c) { if (frame == "Null frame") c->SetFrame(NullFrame()); if (frame == "Field frame") c->SetFrame(FieldFrame()); if (frame == "Inset frame") c->SetFrame(InsetFrame()); if (frame == "Outset frame") c->SetFrame(OutsetFrame()); if (frame == "Thin inset frame") c->SetFrame(ThinInsetFrame()); if (frame == "Thin outset frame") c->SetFrame(ThinOutsetFrame()); if (frame == "Black frame") c->SetFrame(BlackFrame()); if (frame == "Button frame") c->SetFrame(ButtonFrame()); if (frame == "Top separator frame") c->SetFrame(TopSeparatorFrame()); if (frame == "Left separator frame") c->SetFrame(LeftSeparatorFrame()); if (frame == "Right separator frame") c->SetFrame(RightSeparatorFrame()); if (frame == "Bottom separator frame") c->SetFrame(BottomSeparatorFrame()); } } UpdateItemList(); UpdateChildAllPos(); }