// write using any key and path public void WriteIniValueEx(string PutVariable, string PutValue, string IniKey, string filepath) { int HIKEY = 0; int VAR = 0; int VARENDOFLINE = 0; int NF = FileSystem.FreeFile(); string ReadKey = Environment.NewLine + IniKey + "\r"; int KEYLEN = Strings.Len(ReadKey); string ReadVariable = "\n" + PutVariable.ToLower() + "="; FileSystem.FileClose(NF); FileSystem.FileOpen(NF, filepath, OpenMode.Binary, OpenAccess.Default, OpenShare.Default, -1); FileSystem.FileClose(NF); (new FileInfo(filepath)).Attributes = FileAttributes.Archive; FileSystem.FileOpen(NF, filepath, OpenMode.Input, OpenAccess.Default, OpenShare.Default, -1); string temp = FileSystem.InputString(NF, (int)FileSystem.LOF(NF)); temp = Environment.NewLine + temp + "[]"; FileSystem.FileClose(NF); string LcaseTemp = temp.ToLower(); int LOKEY = (LcaseTemp.IndexOf(ReadKey) + 1); if (LOKEY == 0) { goto AddKey; } HIKEY = Strings.InStr(LOKEY + KEYLEN, LcaseTemp, "[", CompareMethod.Binary); VAR = Strings.InStr(LOKEY, LcaseTemp, ReadVariable, CompareMethod.Binary); if (VAR > HIKEY || VAR < LOKEY) { goto AddVariable; } goto RenewVariable; AddKey: temp = temp.Substring(0, Math.Min(Strings.Len(temp) - 2, temp.Length)); temp = temp + Environment.NewLine + Environment.NewLine + IniKey + Environment.NewLine + PutVariable + "=" + PutValue; goto TrimFinalString; AddVariable: temp = temp.Substring(0, Math.Min(Strings.Len(temp) - 2, temp.Length)); temp = temp.Substring(0, Math.Min(LOKEY + KEYLEN, temp.Length)) + PutVariable + "=" + PutValue + Environment.NewLine + temp.Substring(LOKEY + KEYLEN); goto TrimFinalString; RenewVariable: temp = temp.Substring(0, Math.Min(Strings.Len(temp) - 2, temp.Length)); VARENDOFLINE = Strings.InStr(VAR, temp, "\r", CompareMethod.Binary); temp = temp.Substring(0, Math.Min(VAR, temp.Length)) + PutVariable + "=" + PutValue + temp.Substring(VARENDOFLINE - 1); goto TrimFinalString; TrimFinalString: temp = temp.Substring(1); while ((temp.IndexOf(Environment.NewLine + Environment.NewLine + Environment.NewLine) + 1) != 0) { temp = StringsHelper.Replace(temp, Environment.NewLine + Environment.NewLine + Environment.NewLine, Environment.NewLine + Environment.NewLine, 1, -1, CompareMethod.Binary); } ; while (String.CompareOrdinal(temp.Substring(Math.Max(temp.Length - 1, 0)), "\r") <= 0) { temp = temp.Substring(0, Math.Min(Strings.Len(temp) - 1, temp.Length)); } ; while (String.CompareOrdinal(temp.Substring(0, Math.Min(1, temp.Length)), "\r") <= 0) { temp = temp.Substring(1); } ; FileSystem.FileOpen(NF, filepath, OpenMode.Output, OpenAccess.Default, OpenShare.Default, -1); FileSystem.PrintLine(NF, temp); FileSystem.FileClose(NF); }