void saveCfgFile(const char *fn, void *p, int iLen){ CTEditBase b(1024); setCfgFN(b,fn); saveFileW(b.getText(),p,iLen); setOwnerAccessOnly(b.getText()); setFileBackgroundReadable(b); }
void save(){ if(!iInitOk)return; if(memcmp(&prevSettings,&g_Settings,sizeof(TG_SETTINS))==0)return; memcpy(&prevSettings,&g_Settings,sizeof(TG_SETTINS)); char dst[4096]; CTEditBase b(4096); setCfgFN(b,G_CFG_FILE_ID); int l=0; #define SAVE_G_CFG_I(_V,_K) l+=snprintf(&dst[l],sizeof(dst)-1-l,"%s: %d\n",#_K,_V); SAVE_G_CFG_I(g_Settings.iPreferDH2K,iPreferDH2K); SAVE_G_CFG_I(g_Settings.iDisableAES256,iDisableAES256); SAVE_G_CFG_I(g_Settings.iDisable256SAS,iDisable256SAS); SAVE_G_CFG_I(g_Settings.iDisableDH2K,iDisableDH2K); SAVE_G_CFG_I(g_Settings.iDisableECDH384,iDisableECDH384); SAVE_G_CFG_I(g_Settings.iDisableECDH256,iDisableECDH256); SAVE_G_CFG_I(g_Settings.iEnableSHA384,iEnableSHA384); SAVE_G_CFG_I(g_Settings.iDisableSkein,iDisableSkein); SAVE_G_CFG_I(g_Settings.iDisableTwofish,iDisableTwofish); SAVE_G_CFG_I(g_Settings.iPreferNIST,iPreferNIST); SAVE_G_CFG_I(g_Settings.iDisableBernsteinCurve3617,iDisableBernsteinCurve3617); SAVE_G_CFG_I(g_Settings.iDisableBernsteinCurve25519,iDisableBernsteinCurve25519); SAVE_G_CFG_I(g_Settings.iHideCfg,iHideCfg); SAVE_G_CFG_I(g_Settings.iDontSimplifyVideoUI,iDontSimplifyVideoUI); SAVE_G_CFG_I(g_Settings.iDisplayUnsolicitedVideo,iDisplayUnsolicitedVideo); SAVE_G_CFG_I(g_Settings.iAudioUnderflow,iAudioUnderflow); SAVE_G_CFG_I(g_Settings.iRetroRingtone,iRetroRingtone); SAVE_G_CFG_I(g_Settings.iSASConfirmClickCount,iSASConfirmClickCount);//TODO remove SAVE_G_CFG_I(g_Settings.iShowRXLed,iShowRXLed); SAVE_G_CFG_I(g_Settings.iKeepScreenOnIfBatOk,iKeepScreenOnIfBatOk); SAVE_G_CFG_I(g_Settings.iDisableSkeinHash, iDisableSkeinHash); l+=snprintf(&dst[l],sizeof(dst)-1-l,"%s: %s\n","szLastUsedAccount",g_Settings.szLastUsedAccount); l+=snprintf(&dst[l],sizeof(dst)-1-l,"%s: %s\n","szRingTone",g_Settings.szRingTone); saveFileW(b.getText(),&dst[0],l); setFileBackgroundReadable(b); }
int saveCfgFile(int iNextPosToTest, void *p, int iLen){ char fn[64]; CTEditBase b(1024); #define MAX_CFG_FILES 10000 for(int i=iNextPosToTest;i<MAX_CFG_FILES;i++){ if(i)snprintf(fn, sizeof(fn)-1, "tivi_cfg%d.xml", i); else strcpy(fn,"tivi_cfg.xml"); setCfgFN(b, fn); if(!isFileExistsW(b.getText())){ //save into i pos iNextPosToTest=i+1; break; } } saveFileW(b.getText(),p,iLen); setOwnerAccessOnly(b.getText()); setFileBackgroundReadable(b); return iNextPosToTest; }
void init(){ if(iInitOk)return; iInitOk=1; CTEditBase b(4096); setCfgFN(b,G_CFG_FILE_ID); g_Settings.iEnableSHA384=1; g_Settings.iSASConfirmClickCount=10; int iCfgLen=0; char *p=loadFileW(b.getText(),iCfgLen); if(!p){iInitOk=0;return;} setFileBackgroundReadable(b); // puts(p); int getCFGItemSz(char *ret, int iMaxSize, char *p, int iCfgLen, const char *key); int getCFGItemI(int *ret, char *p, int iCfgLen, const char *key); #define M_FNC_INT_T(_DST,_K) getCFGItemI(&(_DST),p,iCfgLen,#_K) M_FNC_INT_T(g_Settings.iDisableDH2K,iDisableDH2K); M_FNC_INT_T(g_Settings.iPreferDH2K,iPreferDH2K); M_FNC_INT_T(g_Settings.iDisableAES256,iDisableAES256); M_FNC_INT_T(g_Settings.iDisable256SAS,iDisable256SAS); M_FNC_INT_T(g_Settings.iDisableECDH384,iDisableECDH384); M_FNC_INT_T(g_Settings.iDisableECDH256,iDisableECDH256); M_FNC_INT_T(g_Settings.iEnableSHA384,iEnableSHA384); M_FNC_INT_T(g_Settings.iDisableSkein,iDisableSkein); M_FNC_INT_T(g_Settings.iDisableTwofish,iDisableTwofish); int r = M_FNC_INT_T(g_Settings.iPreferNIST,iPreferNIST); if( r<0 ){//iPreferNIST is not detected g_Settings.iPreferNIST = 0; g_Settings.iDisableTwofish = 0;//must override here it was previously 1 g_Settings.iDisableSkein = 0; } M_FNC_INT_T(g_Settings.iDisableBernsteinCurve25519,iDisableBernsteinCurve25519); M_FNC_INT_T(g_Settings.iDisableBernsteinCurve3617,iDisableBernsteinCurve3617); if(g_Settings.iDisableECDH384==0){ g_Settings.iEnableSHA384=1; g_Settings.iDisableAES256=0; } M_FNC_INT_T(g_Settings.iHideCfg,iHideCfg); M_FNC_INT_T(g_Settings.iDontSimplifyVideoUI,iDontSimplifyVideoUI); M_FNC_INT_T(g_Settings.iDisplayUnsolicitedVideo,iDisplayUnsolicitedVideo); M_FNC_INT_T(g_Settings.iAudioUnderflow,iAudioUnderflow); g_Settings.iDontSimplifyVideoUI=1; M_FNC_INT_T(g_Settings.iKeepScreenOnIfBatOk,iKeepScreenOnIfBatOk); M_FNC_INT_T(g_Settings.iShowRXLed,iShowRXLed); M_FNC_INT_T(g_Settings.iDisableSkeinHash,iDisableSkeinHash); M_FNC_INT_T(g_Settings.iRetroRingtone,iRetroRingtone); M_FNC_INT_T(g_Settings.iSASConfirmClickCount,iSASConfirmClickCount); g_Settings.iSASConfirmClickCount=10; strcpy(g_Settings.szRingTone,"Default"); getCFGItemSz(g_Settings.szLastUsedAccount,sizeof(g_Settings.szLastUsedAccount),p,iCfgLen,"szLastUsedAccount"); getCFGItemSz(g_Settings.szRingTone,sizeof(g_Settings.szRingTone),p,iCfgLen,"szRingTone"); memcpy(&prevSettings,&g_Settings,sizeof(TG_SETTINS)); delete p; }