private string _getVersion(string strKey, string strDefault) { IniResItem iri = getIniResItem(strKey); if (iri != null) { return(iri.version); } else { return(strDefault); } }
private void readIniFile0() { #region -- 过程变量定义 -- int nIdx = 0, lineNo = 0; string strLine = ""; StreamReader sr = null; #endregion try { if (!File.Exists(iniFileName)) { throw new Exception("配置文件 " + iniFileName + " 不存在,请检查。"); } sr = File.OpenText(iniFileName); while (sr.Peek() >= 0) { lineNo++; strLine = sr.ReadLine().Trim(); if (strLine.Length < 4) { continue; } else if (strLine.Substring(0, 4).Equals("rem ", StringComparison.CurrentCultureIgnoreCase)) { continue; } else { nIdx = strLine.IndexOf("="); if (nIdx <= 0) { throw new Exception("\n配置文件 " + iniFileName + " 第 " + lineNo + " 行格式不正确,请检查:\n\n" + strLine + "\n"); } IniResItem iri = new IniResItem(); iri.key = strLine.Substring(0, nIdx).Trim(); iri.value = strLine.Substring(nIdx + 1).Trim(); lstIri.Add(iri); } } } catch (Exception e) { throw e; } finally { if (sr != null) { sr.Close(); } } }
public void updateInIResItem(IniResItem resItem) { IniResItem resItemExist = this.getIniResItem(resItem.key); if (resItemExist == null) { this.addInIResItem(resItem); } else { resItemExist.type = resItem.type; resItemExist.method = resItem.method; resItemExist.value = resItem.value; resItemExist.version = resItem.version; } }
public void addInIResItem(IniResItem resItem) { this.lstIri.Add(resItem); }
private void readIniFile1() { #region -- 过程变量定义 -- int nIdx = 0, lineNo = 0; string strLine = ""; string strKeyValue = "", strKey = "", strValue = ""; string[] arrResItem = null; StreamReader sr = null; #endregion try { if (!File.Exists(iniFileName)) { throw new Exception("配置文件 " + iniFileName + " 不存在,请检查。"); } sr = File.OpenText(iniFileName); while (sr.Peek() >= 0) { lineNo++; strLine = sr.ReadLine().Trim(); if (strLine.Length < 4) { continue; } else if (strLine.Substring(0, 4).Equals("rem ", StringComparison.CurrentCultureIgnoreCase)) { continue; } else { IniResItem iri = new IniResItem(); arrResItem = strLine.Split(';'); for (int i = 0; i < arrResItem.Length; i++) { strKeyValue = arrResItem[i]; if (strKeyValue.Trim() == "") { continue; } nIdx = strKeyValue.IndexOf("="); if (nIdx <= 0) { throw new Exception("\n配置文件 " + iniFileName + " 第 " + lineNo + " 行格式不正确,请检查:\n\n" + strLine + "\n"); } strKey = strKeyValue.Substring(0, nIdx).Trim(); strValue = strKeyValue.Substring(nIdx + 1).Trim(); if (strKey.Equals("key", StringComparison.CurrentCultureIgnoreCase)) { iri.key = strValue; } else if (strKey.Equals("type", StringComparison.CurrentCultureIgnoreCase)) { iri.type = strValue; } else if (strKey.Equals("method", StringComparison.CurrentCultureIgnoreCase)) { iri.method = strValue; } else if (strKey.Equals("value", StringComparison.CurrentCultureIgnoreCase)) { iri.value = strValue; } else if (strKey.Equals("version", StringComparison.CurrentCultureIgnoreCase)) { iri.version = strValue; } else if (strKey.Equals("path", StringComparison.CurrentCultureIgnoreCase)) { iri.path = strValue; } else { GS.ShowError("未知的 ini 配置项名称:" + strKey + ",已忽略。"); } } lstIri.Add(iri); } } } catch (Exception e) { throw e; } finally { if (sr != null) { sr.Close(); } } }