//写值,如果应用程序名为空,将写第一个找到的 bool INISetting::SetSetting(LPCTSTR szKey,LPCTSTR szValue,LPCTSTR szAppName) { CString sValue; CString sThis; CString sKey; CString sAppName; PtrStruct *pMap; CStringArray aKey; CStringArray aValue; sValue = szValue; sAppName = szAppName; sKey = szKey; sAppName.MakeUpper(); //sKey.MakeUpper(); /* DPrintf("\n *** 当前设的为 文件名: %s",m_sINIFilePath); DPrintf("\n *** 节名: %s",sAppName); DPrintf("\n *** 键名: %s",sKey); DPrintf("\n *** 键值: %s",sValue);*/ if (m_mapStringToMap.Lookup(sAppName,(void*&)pMap)) { BOOL bFind = FALSE; POSITION pp; pp = pMap->Data.GetStartPosition(); int pos; while (pp) { KeyAndValue strTmp; pMap->Data.GetNextAssoc(pp, pos, strTmp); if (strTmp.sKey.CollateNoCase(sKey) == 0) { strTmp.sValue = sValue; pMap->Data.SetAt(pos, strTmp); bFind = TRUE; break; } } if (!bFind) { KeyAndValue strTmp; strTmp.sKey = sKey; strTmp.sValue = sValue; pos++; pMap->Data.SetAt(pos, strTmp); } } else { pMap = new PtrStruct; pMap->sAppName = sAppName; KeyAndValue strTmp; strTmp.sKey = sKey; strTmp.sValue = sValue; int pos = 0; pMap->Data.SetAt(pos, strTmp); m_mapStringToMap.SetAt(pMap->sAppName, pMap); } //2.改文件 aKey.RemoveAll(); aValue.RemoveAll(); aKey.Add(szKey); aValue.Add(sValue); return WriteIni(szAppName,aKey,aValue,m_sINIFilePath); }
BOOL TInifile::EndUpdate() { return WriteIni(); }
BOOL Cfg::ReadIni(WCHAR *user_dir, WCHAR *virtual_dir) { if (!Init(user_dir, virtual_dir)) return FALSE; int i, j; char section[100], key[100], *p; DynBuf buf(MAX_HISTORY_CHAR_BUF); Wstr wbuf(MAX_HISTORY_CHAR_BUF); char *section_array[] = { SRC_HISTORY, DST_HISTORY, DEL_HISTORY, INC_HISTORY, EXC_HISTORY, FROMDATE_HISTORY, TODATE_HISTORY, MINSIZE_HISTORY, MAXSIZE_HISTORY }; bool is_filter_array[] = { false, false, false, true, true, false, false, false, false }; WCHAR ***history_array[] = { &srcPathHistory, &dstPathHistory, &delPathHistory, &includeHistory, &excludeHistory, &fromDateHistory, &toDateHistory, &minSizeHistory, &maxSizeHistory }; /* WCHAR wtestbuf[MAX_HISTORY_CHAR_BUF]; WCHAR *wtest[] = { L"12345", L"abc\\[abc\\]\\", L"aaa\\aaa", L"abc[\\ax]", L"abc[\\ax]\\", L"12[[]345", L"12[[]345\\", L"12\\a3\\[45\\", L"12345", NULL }; for (int i=0; wtest[i]; i++) GetFilterStrCore(wtest[i], wtestbuf); */ srcPathHistory = NULL; dstPathHistory = NULL; delPathHistory = NULL; includeHistory = NULL; excludeHistory = NULL; jobArray = NULL; jobMax = 0; finActArray = NULL; finActMax = 0; ini.SetSection(MAIN_SECTION); iniVersion = ini.GetInt(INI_VERSION_KEY, CUR_INI_VERSION); bufSize = ini.GetInt(BUFSIZE_KEY, DEFAULT_BUFSIZE); maxRunNum = ini.GetInt(MAXRUNNUM_KEY, DEFAULT_MAXRUNNUM); maxTransSize = ini.GetInt(MAXTRANSSIZE_KEY, DEFAULT_MAXTRANSSIZE); maxOvlNum = ini.GetInt(MAXOVLNUM_KEY, DEFAULT_MAXOVLNUM); maxOvlSize = ini.GetInt(MAXOVLSIZE_KEY, -1); if ((maxTransSize % maxOvlNum)) { maxTransSize = (maxTransSize + maxOvlNum - 1) / maxOvlNum * maxOvlNum; } if (bufSize < maxTransSize * BUFIO_SIZERATIO) { bufSize = maxTransSize * BUFIO_SIZERATIO; } maxOpenFiles = ini.GetInt(MAXOPENFILES_KEY, DEFAULT_MAXOPENFILES); maxAttrSize = ini.GetInt(MAXATTRSIZE_KEY, DEFAULT_MAXATTRSIZE); maxDirSize = ini.GetInt(MAXDIRSIZE_KEY, DEFAULT_MAXDIRSIZE); nbMinSizeNtfs = ini.GetInt(NONBUFMINSIZENTFS_KEY, DEFAULT_NBMINSIZE_NTFS); nbMinSizeFat = ini.GetInt(NONBUFMINSIZEFAT_KEY, DEFAULT_NBMINSIZE_FAT); timeDiffGrace = ini.GetInt(TIMEDIFFGRACE_KEY, 0); isReadOsBuf = ini.GetInt(ISREADOSBUF_KEY, FALSE); isWShareOpen = ini.GetInt(WRITESHAREOPEN_KEY, FALSE); maxHistoryNext = maxHistory = ini.GetInt(MAX_HISTORY_KEY, DEFAULT_MAX_HISTORY); copyMode = ini.GetInt(COPYMODE_KEY, DEFAULT_COPYMODE); copyFlags = ini.GetInt(COPYFLAGS_KEY, DEFAULT_COPYFLAGS); copyUnFlags = ini.GetInt(COPYUNFLAGS_KEY, DEFAULT_COPYUNFLAGS); skipEmptyDir = ini.GetInt(SKIPEMPTYDIR_KEY, DEFAULT_EMPTYDIR); forceStart = ini.GetInt(FORCESTART_KEY, DEFAULT_FORCESTART); ignoreErr = ini.GetInt(IGNORE_ERR_KEY, TRUE); estimateMode = ini.GetInt(ESTIMATE_KEY, 0); diskMode = ini.GetInt(DISKMODE_KEY, 0); netDrvMode = ini.GetInt(NETDRVMODE_KEY, 0); aclReset = ini.GetInt(ACLRESET_KEY, 0); isTopLevel = ini.GetInt(ISTOPLEVEL_KEY, FALSE); isErrLog = ini.GetInt(ISERRLOG_KEY, TRUE); isUtf8Log = ini.GetInt(ISUTF8LOG_KEY, TRUE); fileLogMode = ini.GetInt(FILELOGMODE_KEY, 0); fileLogFlags = ini.GetInt(FILELOGFLAGS_KEY, 0); aclErrLog = ini.GetInt(ACLERRLOG_KEY, FALSE); streamErrLog = ini.GetInt(STREAMERRLOG_KEY, FALSE); debugFlags = ini.GetInt(DEBUGFLAGS_KEY, 0); isRunasButton = ini.GetInt(ISRUNASBUTTON_KEY, FALSE); isSameDirRename = ini.GetInt(ISSAMEDIRRENAME_KEY, TRUE); shextAutoClose = ini.GetInt(SHEXTAUTOCLOSE_KEY, TRUE); shextTaskTray = ini.GetInt(SHEXTTASKTRAY_KEY, FALSE); shextNoConfirm = ini.GetInt(SHEXTNOCONFIRM_KEY, FALSE); shextNoConfirmDel = ini.GetInt(SHEXTNOCONFIRMDEL_KEY, FALSE); execConfirm = ini.GetInt(EXECCONRIM_KEY, FALSE); lcid = ini.GetInt(LCID_KEY, -1); waitTick = ini.GetInt(WAITTICK_KEY, DEFAULT_WAITTICK); isAutoSlowIo = ini.GetInt(ISAUTOSLOWIO_KEY, TRUE); speedLevel = ini.GetInt(SPEEDLEVEL_KEY, SPEED_FULL); alwaysLowIo = ini.GetInt(ALWAYSLOWIO_KEY, FALSE); enableOwdel = ini.GetInt(OWDEL_KEY, FALSE); enableAcl = ini.GetInt(ACL_KEY, FALSE); enableStream = ini.GetInt(STREAM_KEY, FALSE); enableVerify = ini.GetInt(VERIFY_KEY, FALSE); useOverlapIo = ini.GetInt(USEOVERLAPIO_KEY, TRUE); usingMD5 = ini.GetInt(USEMD5_KEY, TRUE); enableNSA = ini.GetInt(NSA_KEY, FALSE); delDirWithFilter= ini.GetInt(DELDIR_KEY, FALSE); enableMoveAttr = ini.GetInt(MOVEATTR_KEY, FALSE); serialMove = ini.GetInt(SERIALMOVE_KEY, TRUE); serialVerifyMove = ini.GetInt(SERIALVERIFYMOVE_KEY, TRUE); isReparse = ini.GetInt(REPARSE_KEY, TRUE); isLinkDest = ini.GetInt(LINKDEST_KEY, FALSE); maxLinkHash = ini.GetInt(MAXLINKHASH_KEY, DEFAULT_LINKHASH); allowContFsize = ini.GetInt(ALLOWCONTFSIZE_KEY, DEFAULT_ALLOWCONTFSIZE); isReCreate = ini.GetInt(RECREATE_KEY, FALSE); isExtendFilter = ini.GetInt(EXTENDFILTER_KEY, FALSE); taskbarMode = ini.GetInt(TASKBARMODE_KEY, 0); finishNotify = ini.GetInt(FINISHNOTIFY_KEY, 1); finishNotifyTout = ini.GetInt(FINISHNOTIFYTOUT_KEY, FINISH_NOTIFY_DEFAULT); infoSpan = ini.GetInt(INFOSPAN_KEY, DEFAULT_INFOSPAN); if (infoSpan < 0 || infoSpan > 2) infoSpan = DEFAULT_INFOSPAN; ini.GetStr(WINPOS_KEY, buf, MAX_PATH, ""); winpos.x = (p = strtok(buf, ", \t")) ? atoi(p) : INVALID_POINTVAL; winpos.y = p && (p = strtok(NULL, ", \t")) ? atoi(p) : INVALID_POINTVAL; winsize.cx = p && (p = strtok(NULL, ", \t")) ? atoi(p) : INVALID_SIZEVAL; winsize.cy = p && (p = strtok(NULL, ", \t")) ? atoi(p) : INVALID_SIZEVAL; ini.GetStr(DRIVEMAP_KEY, driveMap, sizeof(driveMap), ""); ini.GetStr(STATUSFONT_KEY, buf, MAX_HISTORY_CHAR_BUF, ""); IniStrToW(buf, statusFont); statusFontSize = ini.GetInt(STATUSFONTSIZE_KEY, 0); /* logfile */ ini.GetStr(LOGFILE_KEY, buf, MAX_PATH, DEFAULT_FASTCOPYLOG); IniStrToW(buf, wbuf.Buf()); if (wcschr(wbuf.s(), '\\') == NULL) { Wstr wname(wbuf); MakePathW(wbuf.Buf(), userDir, wname.s()); } errLogPath = wcsdup(wbuf.s()); /* History */ for (i=0; i < sizeof(section_array) / sizeof(char *); i++) { char *section_p = section_array[i]; bool &is_filter = is_filter_array[i]; WCHAR **&history = *history_array[i]; ini.SetSection(section_p); history = (WCHAR **)calloc(maxHistory, sizeof(WCHAR *)); for (j=0; j < maxHistory + 30; j++) { wsprintf(key, "%d", j); if (j < maxHistory) { if (is_filter) { GetFilterStr(key, buf, wbuf.Buf()); } else { ini.GetStr(key, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); } history[j] = wcsdup(wbuf.s()); } else if (!ini.DelKey(key)) break; } } /* Job */ for (i=0; i < JOB_MAX; i++) { Job job; wsprintf(section, FMT_JOB_KEY, i); ini.SetSection(section); if (ini.GetStr(TITLE_KEY, buf, MAX_HISTORY_CHAR_BUF) <= 0) break; IniStrToW(buf, wbuf.Buf()); job.title = wcsdup(wbuf.s()); ini.GetStr(SRC_KEY, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); job.src = wcsdup(wbuf.s()); ini.GetStr(DST_KEY, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); job.dst = wcsdup(wbuf.s()); ini.GetStr(CMD_KEY, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); job.cmd = wcsdup(wbuf.s()); GetFilterStr(INCLUDE_KEY, buf, wbuf.Buf()); job.includeFilter = wcsdup(wbuf.s()); GetFilterStr(EXCLUDE_KEY, buf, wbuf.Buf()); job.excludeFilter = wcsdup(wbuf.s()); ini.GetStr(FROMDATE_KEY, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); job.fromDateFilter = wcsdup(wbuf.s()); ini.GetStr(TODATE_KEY, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); job.toDateFilter = wcsdup(wbuf.s()); ini.GetStr(MINSIZE_KEY, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); job.minSizeFilter = wcsdup(wbuf.s()); ini.GetStr(MAXSIZE_KEY, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); job.maxSizeFilter = wcsdup(wbuf.s()); job.estimateMode = ini.GetInt(ESTIMATE_KEY, 0); job.diskMode = ini.GetInt(DISKMODE_KEY, 0); job.ignoreErr = ini.GetInt(IGNORE_ERR_KEY, TRUE); job.enableOwdel = ini.GetInt(OWDEL_KEY, FALSE); job.enableAcl = ini.GetInt(ACL_KEY, FALSE); job.enableStream = ini.GetInt(STREAM_KEY, FALSE); job.enableVerify = ini.GetInt(VERIFY_KEY, FALSE); job.isFilter = ini.GetInt(FILTER_KEY, FALSE); job.bufSize = ini.GetInt(BUFSIZE_KEY, DEFAULT_BUFSIZE); if (job.bufSize < maxTransSize * BUFIO_SIZERATIO) { job.bufSize = maxTransSize * BUFIO_SIZERATIO; } AddJobW(&job); } /* FinAct */ for (i=0; i < FINACT_MAX; i++) { FinAct act; wsprintf(buf, FMT_FINACT_KEY, i); ini.SetSection(buf); if (ini.GetStr(TITLE_KEY, buf, MAX_HISTORY_CHAR_BUF) <= 0) break; IniStrToW(buf, wbuf.Buf()); act.title = wcsdup(wbuf.Buf()); ini.GetStr(SOUND_KEY, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); act.sound = wcsdup(wbuf.s()); ini.GetStr(CMD_KEY, buf, MAX_HISTORY_CHAR_BUF); IniStrToW(buf, wbuf.Buf()); act.command = wcsdup(wbuf.s()); act.flags = ini.GetInt(FLAGS_KEY, 0); if (ini.GetStr(SHUTDOWNTIME_KEY, buf, MAX_HISTORY_CHAR_BUF) > 0) { act.shutdownTime = strtol(buf, 0, 10); } AddFinActW(&act); } if (::GetFileAttributesW(ini.GetIniFileNameW()) == 0xffffffff) { WriteIni(); } needIniConvert = FALSE; return TRUE; }