void HPreferences::InitTextFont(BFont* font) { font_family ff; font_style fs; be_fixed_font->GetFamilyAndStyle(&ff, &fs); strcpy(ff, GetPrefString(prf_S_FontFamily, ff)); strcpy(fs, GetPrefString(prf_S_FontStyle, fs)); font->SetFamilyAndStyle(ff, fs); font->SetSize(GetPrefDouble(prf_D_FontSize, be_plain_font->Size())); }
int Preferences::SaveToRegistry(void) { LOGI("Saving preferences to registry"); fColumnLayout.SaveToRegistry(kColumnSect); int i; for (i = 0; i < kPrefNumLastRegistry; i++) { if (fPrefMaps[i].registryKey == NULL) continue; switch (fPrefMaps[i].type) { case kBool: WriteBool(fPrefMaps[i].registrySection, fPrefMaps[i].registryKey, GetPrefBool(fPrefMaps[i].num)); break; case kLong: WriteInt(fPrefMaps[i].registrySection, fPrefMaps[i].registryKey, GetPrefLong(fPrefMaps[i].num)); break; case kString: WriteString(fPrefMaps[i].registrySection, fPrefMaps[i].registryKey, GetPrefString(fPrefMaps[i].num)); break; default: LOGW("Invalid type %d on num=%d", fPrefMaps[i].type, i); ASSERT(false); break; } } return 0; }
int Preferences::LoadFromRegistry(void) { CString sval; bool bval; long lval; LOGI("Loading preferences from registry"); fColumnLayout.LoadFromRegistry(kColumnSect); int i; for (i = 0; i < kPrefNumLastRegistry; i++) { if (fPrefMaps[i].registryKey == NULL) continue; switch (fPrefMaps[i].type) { case kBool: bval = GetPrefBool(fPrefMaps[i].num); SetPrefBool(fPrefMaps[i].num, GetBool(fPrefMaps[i].registrySection, fPrefMaps[i].registryKey, bval)); break; case kLong: lval = GetPrefLong(fPrefMaps[i].num); SetPrefLong(fPrefMaps[i].num, GetInt(fPrefMaps[i].registrySection, fPrefMaps[i].registryKey, lval)); break; case kString: sval = GetPrefString(fPrefMaps[i].num); SetPrefString(fPrefMaps[i].num, GetString(fPrefMaps[i].registrySection, fPrefMaps[i].registryKey, sval)); break; default: LOGW("Invalid type %d on num=%d", fPrefMaps[i].type, i); ASSERT(false); break; } } return 0; }
void Preferences::InitFolders(void) { CString path; if (GetMyDocuments(&path)) { SetPrefString(kPrOpenArchiveFolder, path); SetPrefString(kPrConvertArchiveFolder, path); SetPrefString(kPrAddFileFolder, path); SetPrefString(kPrExtractFileFolder, path); SetPrefString(kPrOpenWAVFolder, path); } else { WCHAR buf[MAX_PATH]; ::GetCurrentDirectory(NELEM(buf), buf); SetPrefString(kPrOpenArchiveFolder, buf); SetPrefString(kPrConvertArchiveFolder, buf); SetPrefString(kPrAddFileFolder, buf); SetPrefString(kPrExtractFileFolder, buf); SetPrefString(kPrOpenWAVFolder, buf); } LOGD("Default folder is '%ls'", GetPrefString(kPrExtractFileFolder)); }
Error Win32Prefs:: SetDefaults() { char cwd[MAX_PATH]= {0x00}; char path[MAX_PATH]; char buf[1024]; uint32 size; bool dummyBool; //int32 dummyInt32; // Where are we starting the program from? GetCurrentDirectory(sizeof(cwd), cwd); // set install directory value size = sizeof(buf); if (GetPrefString(kInstallDirPref, buf, &size) == kError_NoPrefValue) SetPrefString(kInstallDirPref, cwd); // set music directory value size = sizeof(buf); if (GetPrefString(kSaveMusicDirPref, buf, &size) == kError_NoPrefValue) { strcpy(path, cwd); strcat(path, "\\"); strcat(path, "My Music"); SetPrefString(kSaveMusicDirPref, path); } // set watch this dir value size = sizeof(buf); if (GetPrefString(kWatchThisDirectoryPref, buf, &size) == kError_NoPrefValue) { strcpy(path, cwd); strcat(path, "\\"); strcat(path, "My Music"); SetPrefString(kWatchThisDirectoryPref, path); } // set db directory value size = sizeof(buf); if (GetPrefString(kDatabaseDirPref, buf, &size) == kError_NoPrefValue) { strcpy(path, cwd); strcat(path, "\\"); strcat(path, "db"); SetPrefString(kDatabaseDirPref, path); } // set default ui value size = sizeof(buf); if (GetPrefString(kUIPref, buf, &size) == kError_NoPrefValue) SetPrefString(kUIPref, kDefaultUI); // set default pmo value size = sizeof(buf); if (GetPrefString(kPMOPref, buf, &size) == kError_NoPrefValue) SetPrefString(kPMOPref, kDefaultPMO); // set default open/save dlg path value size = sizeof(buf); if (GetPrefString(kOpenSaveDirPref, buf, &size) == kError_NoPrefValue) SetPrefString(kOpenSaveDirPref, cwd); // set default for window staying on top if (GetPrefBoolean(kStayOnTopPref, &dummyBool) == kError_NoPrefValue) SetPrefBoolean(kStayOnTopPref, kDefaultStayOnTop); // set default for minimizing to tray if (GetPrefBoolean(kLiveInTrayPref, &dummyBool) == kError_NoPrefValue) SetPrefBoolean(kLiveInTrayPref, kDefaultLiveInTray); Preferences::SetDefaults(); return kError_NoErr; }
Error Win32Prefs:: Initialize() { LONG result; uint32 length; char path[MAX_PATH] = {0x00}; char cwd[MAX_PATH]= {0x00}; Error error = kError_UnknownErr; // Where are we starting the program from? GetCurrentDirectory(sizeof(cwd), cwd); if(m_prefsKey) { // people DO move their apps around on windows length = sizeof(path); error = GetPrefString(kInstallDirPref, path, &length); char foo[MAX_PATH] = {0x00}; sprintf(foo,"%s\\freeamp.exe",cwd); WIN32_FIND_DATA win32fd; // check for freeamp exe in cwd HANDLE h = FindFirstFile(foo, &win32fd); if (h != INVALID_HANDLE_VALUE) { //if (win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if(IsError(error) || strcmp(cwd, path)) { result = RegSetValueEx( m_prefsKey, kInstallDirPref, NULL, REG_SZ, (LPBYTE)cwd, strlen(cwd) + 1); strcat(cwd, "\\db"); result = RegSetValueEx( m_prefsKey, kDatabaseDirPref, NULL, REG_SZ, (LPBYTE)cwd, strlen(cwd) + 1); } } FindClose(h); } error = kError_NoErr; } else // keys need to be created for the first time { DWORD disposition; HKEY freeampKey; HKEY versionKey; // create the main key in the windows registry result = RegCreateKeyEx(kMainKey, kFreeAmpKey, NULL, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &freeampKey, &disposition); if(result == ERROR_SUCCESS) { // create the version key under the freeamp key result = RegCreateKeyEx(freeampKey, kFreeAmpVersionKey, NULL, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &versionKey, &disposition); } if(result == ERROR_SUCCESS) { // create the version key under the freeamp key result = RegCreateKeyEx(versionKey, kMainComponentKey, NULL, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &m_prefsKey, &disposition); } if(result != ERROR_SUCCESS) error = kError_NoPrefs; RegCloseKey(freeampKey); RegCloseKey(versionKey); } SetDefaults(); Save(); return error; }