void ReadWayPoints(WayPointList &way_points, RasterTerrain &terrain) { StartupStore(TEXT("ReadWayPoints\n")); TCHAR szFile1[MAX_PATH] = TEXT("\0"); TCHAR szFile2[MAX_PATH] = TEXT("\0"); bool file_embedded = false; // JMW TODO protect with mutex (whole waypoint list class) CloseWayPoints(way_points); GetRegistryString(szRegistryWayPointFile, szFile1, MAX_PATH); SetRegistryString(szRegistryWayPointFile, TEXT("\0")); if (_tcslen(szFile1)>0) { ExpandLocalPath(szFile1); } else { file_embedded = true; GetRegistryString(szRegistryMapFile, szFile1, MAX_PATH); ExpandLocalPath(szFile1); _tcscat(szFile1, TEXT("/")); _tcscat(szFile1, TEXT("waypoints.xcw")); } globalFileNum = 0; if (ReadWayPointFile(szFile1, way_points, terrain)) { // read OK, so set the registry to the actual file name if (!file_embedded) { printf("save\n"); ContractLocalPath(szFile1); SetRegistryString(szRegistryWayPointFile, szFile1); } } else { StartupStore(TEXT("No waypoint file 1\n")); } // read additional waypoint file GetRegistryString(szRegistryAdditionalWayPointFile, szFile2, MAX_PATH); SetRegistryString(szRegistryAdditionalWayPointFile, TEXT("\0")); if (_tcslen(szFile2)>0){ ExpandLocalPath(szFile2); globalFileNum = 1; if (ReadWayPointFile(szFile2, way_points, terrain)) { // read OK, so set the registry to the actual file name ContractLocalPath(szFile2); SetRegistryString(szRegistryAdditionalWayPointFile, szFile2); } else { StartupStore(TEXT("No waypoint file 2\n")); } } }
/** * Reads the selected LanguageFile into the cache */ void ReadLanguageFile() { StartupStore(TEXT("Loading language file\n")); TCHAR szFile1[MAX_PATH] = TEXT("\0"); FILE *fp=NULL; // Read the language filename from the registry GetRegistryString(szRegistryLanguageFile, szFile1, MAX_PATH); ExpandLocalPath(szFile1); // Reset filename in registry in case language // loading crashes the application SetRegistryString(szRegistryLanguageFile, TEXT("\0")); // If the language file is not set use the default one if (_tcslen(szFile1)==0) { _tcscpy(szFile1,TEXT("default.xcl")); } // Open the language file fp = _tfopen(szFile1, TEXT("rt")); // Return if file error if (fp == NULL) return; // TODO code: Safer sizes, strings etc - use C++ (can scanf restrict length?) TCHAR buffer[2049]; // key from scanf TCHAR key[2049]; // key from scanf TCHAR value[2049]; // value from scanf int found; // Entries found from scanf // Read from the file while ((GetTextData_Size < MAXSTATUSMESSAGECACHE) && _fgetts(buffer, 2048, fp) && ((found = _stscanf(buffer, TEXT("%[^#=]=%[^\r\n][\r\n]"), key, value)) != EOF)) { // Check valid line? if ((found != 2) || key[0] == 0 || value[0] == 0) continue; // Save parsed translation to the cache GetTextData[GetTextData_Size].key = StringMallocParse(key); GetTextData[GetTextData_Size].text = StringMallocParse(value); // Global counter GetTextData_Size++; } // file was OK, so save filename to registry again ContractLocalPath(szFile1); SetRegistryString(szRegistryLanguageFile, szFile1); fclose(fp); }
bool StoreWindowPosition(HWND hwnd, const char *szWindowName, const char *szSubKey, bool fStoreSize) { RECT winpos; char regstr[100]; if (IsZoomed(hwnd)) return SetRegistryString(szSubKey,szWindowName,"Maximized"); if (IsIconic(hwnd)) return SetRegistryString(szSubKey,szWindowName,"Minimized"); if (!GetWindowRect(hwnd,&winpos)) return false; if (fStoreSize) sprintf(regstr,"%ld,%ld,%ld,%ld",winpos.left,winpos.top,winpos.right-winpos.left,winpos.bottom-winpos.top); else sprintf(regstr,"%ld,%ld",winpos.left,winpos.top); return SetRegistryString(szSubKey,szWindowName,regstr); }
void RegistryVar::setString(UINT id, LPCTSTR value, HKEY root) { CString pathname; pathname.LoadString(id); SetRegistryString(root, pathname, value); }
BOOL SetRegistryString(HKEY root, const CString & path, const CString & var, const CString & val) { CString s; s = path; s += _T("\\"); s += var; return SetRegistryString(root, s, val); } // SetRegistryString
int C4RankSystem::Init(const char *szRegister, const char *szDefRanks, int iRankBase) { // Init SCopy(szRegister,Register,256); RankBase=iRankBase; // Check registry for present rank names and set defaults #ifdef _WIN32 int crank=0; char rankname[C4MaxName+1],keyname[30]; BOOL Checking=TRUE; while (Checking) { sprintf(keyname,"Rank%03d",crank+1); if (GetRegistryString(Register,keyname,rankname,C4MaxName+1)) { // Rank present crank++; } else { // Rank not defined, check for default if (SCopySegment(szDefRanks,crank,rankname,'|',C4MaxName) && SetRegistryString(Register,keyname,rankname)) crank++; else Checking=FALSE; } } return crank; #else // clear any loaded rank names Clear(); if (!szDefRanks) return 0; // make a copy szRankNames = new char[strlen(szDefRanks) + 1]; strcpy (szRankNames, szDefRanks); // split into substrings by replacing the | with zeros for (char * p = szRankNames; *p; ++p) if (*p == '|') { *p = 0; ++iRankNum; } ++ iRankNum; // The last rank is already terminated by zero // build a list of substrings pszRankNames = new char *[iRankNum]; char * p = szRankNames; for (int i = 0; i < iRankNum; ++i) { pszRankNames[i] = p; p += strlen(p) + 1; } return iRankNum; #endif }
BOOL SetRegistryString(HKEY root, const CString & path, UINT var, const CString & val) { CString s; s = path; s += _T("\\"); CString t; t.LoadString(var); s += t; return SetRegistryString(root, s, val); } // SetRegistryString
BOOL C4RankSystem::Check(int iRank, const char *szDefRankName) { #ifdef _WIN32 char rankname[C4MaxName+1],keyname[30]; sprintf(keyname,"Rank%03d",iRank); if (GetRegistryString(Register,keyname,rankname,C4MaxName+1)) return FALSE; if (!szDefRankName || (SLen(szDefRankName)>C4MaxName)) return FALSE; return SetRegistryString(Register,keyname,szDefRankName); #else return TRUE; #endif }
bool C4RankSystem::Check(int iRank, const char *szDefRankName) { #ifdef _WIN32 char keyname[30]; sprintf(keyname,"Rank%03d",iRank); if (!GetRegistryString(Register,keyname).isNull()) return false; if (!szDefRankName || (SLen(szDefRankName)>C4MaxName)) return false; return SetRegistryString(Register,keyname,szDefRankName); #else return true; #endif }
void SaveValues(const TCHAR * FontRegKey ) { // update reg key for font TCHAR sValue [256]; wsprintf(sValue,TEXT("%d,%d,0,0,%d,%d,0,0,0,0,0,%d,%d,%s"), NewLogFont.lfHeight, NewLogFont.lfWidth, NewLogFont.lfWeight, NewLogFont.lfItalic, NewLogFont.lfQuality, NewLogFont.lfPitchAndFamily, NewLogFont.lfFaceName); SetRegistryString(FontRegKey, sValue); }
void LKReadLanguageFile() { static bool doinit=true; static TCHAR oldLang[4]; if (doinit) { _tcscpy(LKLangSuffix,_T("")); _tcscpy(oldLang,_T("XXX")); doinit=false; } bool english=false; TCHAR szFile1[MAX_PATH] = TEXT("\0"); _tcscpy(LKLangSuffix,_T("")); GetRegistryString(szRegistryLanguageFile, szFile1, MAX_PATH); tryeng: if (_tcslen(szFile1)==0) { _tcscpy(szFile1,_T("%LOCAL_PATH%\\\\_Language\\ENGLISH.LNG")); english=true; } ExpandLocalPath(szFile1); // SetRegistryString(szRegistryLanguageFile, TEXT("\0")); // ? ZZIP_FILE *langFile = zzip_fopen(szFile1, "rb"); if (langFile == NULL) { if (english) { StartupStore(_T("--- CRITIC, NO ENGLISH LANGUAGE FILES!%s"),NEWLINE); // critic point, no default language! BIG PROBLEM here! for (unsigned short i=0; i<MAX_MESSAGES; i++) { LKMessages[i]=NULL; LKMessagesIndex[i]=-1; } return; } else { StartupStore(_T("--- NO LANGUAGE FILE FOUND <%s>, retrying with ENGlish!%s"),szFile1,NEWLINE); _tcscpy(szFile1,_T("")); goto tryeng; } return; } bool found=false; TCHAR sTmp[200]; TCHAR mylang[30]; while (ReadULine(langFile, sTmp, countof(sTmp))) { if (_tcslen(sTmp)<3) continue; if ((sTmp[0]=='L')&&(sTmp[1]=='=')) { _tcscpy(mylang,&sTmp[2]); for (unsigned short i=0; i<_tcslen(mylang); i++) { if (mylang[i]=='\r' || mylang[i]=='\n') { mylang[i]='\0'; break; } } found=true; break; } } if (found) { if (_tcslen(mylang)>3) mylang[3]='\0'; _tcscpy(LKLangSuffix,mylang); } if (_tcscmp(oldLang,LKLangSuffix)!=0) { if ( !LKLoadMessages(false) ) { // force reload of english if (_tcscmp(_T("ENG"),LKLangSuffix) == 0 ) { StartupStore(_T("... CRITICAL, no english langauge available!%s"),NEWLINE); } else { StartupStore(_T("... LoadText failed, fallback to english language\n")); _tcscpy(szFile1,_T("%LOCAL_PATH%\\\\_Language\\ENGLISH.LNG")); SetRegistryString(szRegistryLanguageFile, szFile1); _tcscpy(LKLangSuffix,_T("ENG")); LKLoadMessages(false); } } else { _tcscpy(oldLang,mylang); // Now overload english messages filling gaps in translations // only if current lang is not english of course: no reason to load it twice if (_tcscmp(_T("ENG"),LKLangSuffix) != 0 ) { _tcscpy(LKLangSuffix,_T("ENG")); LKLoadMessages(true); _tcscpy(LKLangSuffix,oldLang); } } } zzip_fclose(langFile); return; }
void StatusMessageList::LoadFile() { StartupStore(TEXT("Loading status file\n")); TCHAR szFile1[MAX_PATH] = TEXT("\0"); FILE *fp=NULL; // Open file from registry GetRegistryString(szRegistryStatusFile, szFile1, MAX_PATH); ExpandLocalPath(szFile1); SetRegistryString(szRegistryStatusFile, TEXT("\0")); if (_tcslen(szFile1)>0) fp = _tfopen(szFile1, TEXT("rt")); // Unable to open file if (fp == NULL) return; // TODO code: Safer sizes, strings etc - use C++ (can scanf restrict length?) TCHAR buffer[2049]; // Buffer for all TCHAR key[2049]; // key from scanf TCHAR value[2049]; // value from scanf int ms; // Found ms for delay const TCHAR **location; // Where to put the data int found; // Entries found from scanf bool some_data; // Did we find some in the last loop... // Init first entry _init_Status(StatusMessageData_Size); some_data = false; /* Read from the file */ while ( (StatusMessageData_Size < MAXSTATUSMESSAGECACHE) && _fgetts(buffer, 2048, fp) && ((found = _stscanf(buffer, TEXT("%[^#=]=%[^\n]\n"), key, value)) != EOF) ) { // Check valid line? If not valid, assume next record (primative, but works ok!) if ((found != 2) || key[0] == 0 || value[0] == 0) { // Global counter (only if the last entry had some data) if (some_data) { StatusMessageData_Size++; some_data = false; _init_Status(StatusMessageData_Size); } } else { location = NULL; if (_tcscmp(key, TEXT("key")) == 0) { some_data = true; // Success, we have a real entry location = &StatusMessageData[StatusMessageData_Size].key; } else if (_tcscmp(key, TEXT("sound")) == 0) { StatusMessageData[StatusMessageData_Size].doSound = true; location = &StatusMessageData[StatusMessageData_Size].sound; } else if (_tcscmp(key, TEXT("delay")) == 0) { if (_stscanf(value, TEXT("%d"), &ms) == 1) StatusMessageData[StatusMessageData_Size].delay_ms = ms; } else if (_tcscmp(key, TEXT("hide")) == 0) { if (_tcscmp(value, TEXT("yes")) == 0) StatusMessageData[StatusMessageData_Size].doStatus = false; } // Do we have somewhere to put this && is it currently empty ? (prevent lost at startup) if (location && (_tcscmp(*location, TEXT("")) == 0)) { // TODO code: this picks up memory lost from no entry, but not duplicates - fix. if (*location) { // JMW fix memory leak free((void*)*location); } *location = StringMallocParse(value); } } } // How many we really got (blank next just in case) StatusMessageData_Size++; _init_Status(StatusMessageData_Size); // file was ok, so save it to registry ContractLocalPath(szFile1); SetRegistryString(szRegistryStatusFile, szFile1); fclose(fp); }
void TopologyStore::Open() { StartupStore(TEXT("OpenTopology\n")); XCSoarInterface::CreateProgressDialog(gettext(TEXT("Loading Topology File..."))); Poco::ScopedRWLock protect(lock, true); // Start off by getting the names and paths static TCHAR szOrigFile[MAX_PATH] = TEXT("\0"); static TCHAR szFile[MAX_PATH] = TEXT("\0"); static TCHAR Directory[MAX_PATH] = TEXT("\0"); for (int z=0; z<MAXTOPOLOGY; z++) { topology_store[z] = 0; } GetRegistryString(szRegistryTopologyFile, szFile, MAX_PATH); ExpandLocalPath(szFile); _tcscpy(szOrigFile,szFile); // make copy of original ContractLocalPath(szOrigFile); // remove it in case it causes a crash (will restore later) SetRegistryString(szRegistryTopologyFile, TEXT("\0")); if (_tcslen(szFile)==0) { // file is blank, so look for it in a map file static TCHAR szMapFile[MAX_PATH] = TEXT("\0"); GetRegistryString(szRegistryMapFile, szMapFile, MAX_PATH); if (_tcslen(szMapFile)==0) { return; } ExpandLocalPath(szMapFile); // Look for the file within the map zip file... _tcscpy(Directory,szMapFile); _tcscat(Directory,TEXT("/")); szFile[0]=0; _tcscat(szFile,Directory); _tcscat(szFile,TEXT("topology.tpl")); } else { ExtractDirectory(Directory,szFile); } // Ready to open the file now.. static ZZIP_FILE* zFile; char zfilename[MAX_PATH]; unicode2ascii(szFile, zfilename, MAX_PATH); zFile = zzip_fopen(zfilename, "rt"); if (!zFile) { StartupStore(TEXT("No topology file\n%s\n"), szFile); return; } TCHAR ctemp[80]; TCHAR TempString[READLINE_LENGTH+1]; TCHAR ShapeName[50]; double ShapeRange; long ShapeIcon; long ShapeField; TCHAR wShapeFilename[MAX_PATH]; TCHAR *Stop; int numtopo = 0; char ShapeFilename[MAX_PATH]; while(ReadString(zFile,READLINE_LENGTH,TempString)) { if((_tcslen(TempString) > 0) && (_tcsstr(TempString,TEXT("*")) != TempString)) // Look For Comment { BYTE red, green, blue; // filename,range,icon,field // File name PExtractParameter(TempString, ctemp, 0); _tcscpy(ShapeName, ctemp); _tcscpy(wShapeFilename, Directory); _tcscat(wShapeFilename,ShapeName); _tcscat(wShapeFilename,TEXT(".shp")); #ifdef _UNICODE WideCharToMultiByte( CP_ACP, 0, wShapeFilename, _tcslen(wShapeFilename)+1, ShapeFilename, 200, NULL, NULL); #else strcpy(ShapeFilename, wShapeFilename); #endif // Shape range PExtractParameter(TempString, ctemp, 1); ShapeRange = StrToDouble(ctemp,NULL); // Shape icon PExtractParameter(TempString, ctemp, 2); ShapeIcon = _tcstol(ctemp, &Stop, 10); // Shape field for text display // sjt 02NOV05 - field parameter enabled PExtractParameter(TempString, ctemp, 3); if (_istalnum(ctemp[0])) { ShapeField = _tcstol(ctemp, &Stop, 10); ShapeField--; } else { ShapeField = -1; } // Red component of line / shading colour PExtractParameter(TempString, ctemp, 4); red = (BYTE)_tcstol(ctemp, &Stop, 10); // Green component of line / shading colour PExtractParameter(TempString, ctemp, 5); green = (BYTE)_tcstol(ctemp, &Stop, 10); // Blue component of line / shading colour PExtractParameter(TempString, ctemp, 6); blue = (BYTE)_tcstol(ctemp, &Stop, 10); if ((red==64) && (green==96) && (blue==240)) { // JMW update colours to ICAO standard red = 85; // water colours green = 160; blue = 255; } if (ShapeField<0) { Topology* newtopo; newtopo = new Topology(ShapeFilename, Color(red,green,blue)); topology_store[numtopo] = newtopo; } else { TopologyLabel *newtopol; newtopol = new TopologyLabel(ShapeFilename, Color(red,green,blue), ShapeField); topology_store[numtopo] = newtopol; } if (ShapeIcon!=0) topology_store[numtopo]->loadBitmap(ShapeIcon); topology_store[numtopo]->scaleThreshold = ShapeRange; numtopo++; } } zzip_fclose(zFile); // file was OK, so save it SetRegistryString(szRegistryTopologyFile, szOrigFile); }
void RasterTerrain::OpenTerrain(void) { terrain_initialised = false; StartupStore(TEXT(". Loading Terrain... %s"),NEWLINE); CreateProgressDialog(gettext(TEXT("_@M900_"))); // Loading Terrain File... TCHAR szFile[MAX_PATH] = _T("\0"); _tcscpy(szFile,szTerrainFile); TCHAR szOrigFile[MAX_PATH] = _T("\0"); ExpandLocalPath(szFile); _tcscpy(szOrigFile, szFile); ContractLocalPath(szOrigFile); // If no terrain will be found, the registry will be invalid on next run _tcscpy(szTerrainFile,_T("")); #ifdef LKMTERRAIN static TCHAR szMFile[MAX_PATH] = TEXT("\0"); if (_tcslen(szFile)==0) { StartupStore(_T(". NO TERRAIN file configured%s"),NEWLINE); _tcscpy(szMFile,szMapFile); ExpandLocalPath(szMFile); _tcscpy(szFile,szMFile); #ifdef JP2000 _tcscat(szFile, _T("/terrain.jp2")); StartupStore(_T(". Attempting to use JP2 <%s> inside mapfile%s"),szFile,NEWLINE); // support terrain.dat inside xcm files if (CreateTerrainMap(szFile)) { SetRegistryString(szRegistryTerrainFile, szOrigFile); terrain_initialised = true; return; } else { _tcscpy(szFile,szMFile); _tcscat(szFile, _T("/terrain.dem")); StartupStore(_T(". Attempting to use DEM <%s> inside mapfile%s"),szFile,NEWLINE); } #else _tcscpy(szFile,szMFile); _tcscat(szFile, _T("/terrain.dem")); StartupStore(_T(". Attempting to use DEM <%s> inside mapfile%s"),szFile,NEWLINE); #endif } if (CreateTerrainMap(szFile)) { _tcscpy(szTerrainFile,szOrigFile); terrain_initialised = true; return; } else { _tcscpy(szFile,szMFile); _tcscat(szFile, _T("/terrain.dat")); StartupStore(_T(". Attempting to use DAT <%s> inside mapfile%s"),szFile,NEWLINE); if (CreateTerrainMap(szFile)) { _tcscpy(szTerrainFile,szOrigFile); terrain_initialised = true; return; } } #else if ( (_tcslen(szFile)>0) && ( _tcsstr(szFile, _T(".DEM")) || _tcsstr(szFile, _T(".dem")) ) ) { if (CreateTerrainMap(szFile)) { _tcscpy(szterrainFile,szOrigFile); terrain_initialised = true; return; } else { StartupStore(_T("... INVALID TERRAIN file <%s>%s"),szFile,NEWLINE); } } #endif if (TerrainMap) { TerrainMap->Close(); delete TerrainMap; TerrainMap = NULL; } terrain_initialised = false; StartupStore(_T(". NO TERRAIN file available.%s"),NEWLINE); }