protected internal IniItem(string name, string value, IniType type, string comment) { Name = name; Value = value; Type = type; Comment = comment; }
/// <summary> /// Initializes a new instance of the System.Ini.IniProperty class. Generates random key. /// </summary> /// <param name="section">The section of the property.</param> /// <param name="type">The type of the property.</param> /// <param name="value">The value of the property.</param> public IniProperty(string section, IniType type, string value) { this.Key = null; this.Section = section; this.Type = type; this.Value = value; }
/// <summary> /// Reads an INI section. /// </summary> private void ReadSection() { int ch = -1; iniType = IniType.Section; ch = ReadChar(); // consume "[" while (true) { ch = PeekChar(); if (ch == ']') { break; } if (EndOfLine(ch)) { throw new IniException(this, "Expected section end (])"); } this.name.Append((char)ReadChar()); } ConsumeToEnd(); // all after '[' is garbage RemoveTrailingWhitespace(this.name); }
/// <include file='IniItem.xml' path='//Constructor[@name="Constructor"]/docs/*' /> internal protected IniItem(string name, string value, IniType type, string comment) { iniName = name; iniValue = value; iniType = type; iniComment = comment; }
/// <summary> /// Initializes a new instance of the System.Ini.IniProperty class. /// </summary> /// <param name="section">The section of the property.</param> /// <param name="type">The type of the property.</param> /// <param name="key">The key of the property.</param> /// <param name="value">The value of the property.</param> internal IniProperty(string section, IniType type, string key, string value) { this.Key = key; this.Section = section; this.Type = type; this.Value = value; }
/// <summary> /// Reads a key. /// </summary> private void ReadKey() { int ch = -1; iniType = IniType.Key; while (true) { ch = PeekChar(); if (IsAssign(ch)) { ReadChar(); break; } if (EndOfLine(ch)) { if (acceptNoAssignmentOperator) { break; } throw new IniException(this, String.Format("Expected assignment operator ({0})", assignDelimiters[0])); } this.name.Append((char)ReadChar()); } ReadKeyValue(); SearchForComment(); RemoveTrailingWhitespace(this.name); }
/// <summary> /// Generates and returns a random key by combining the type name + a random number. /// </summary> private string GenerateKey(IniType type) { if (type == IniType.Property) { throw new ArgumentException("Can't generate key for properties.", "type"); } string key = string.Empty; int attempts = 0; // Keep generating a new key until it finds a unused one. // This shouldn't add much delay, if any, unless the INI file is absolutely MASSIVE. do { key = type.ToString() + random.Next(int.MaxValue); if ((attempts++) >= int.MaxValue) { // There is literally no keys left throw new Exception("No random key available."); } } while (this.properties.Contains(key)); return(key); }
/// <summary> /// Adds an IniProperty to the end of the properties list. /// </summary> /// <param name="property">The IniProperty to be added to the end of the properties list.</param> public IniSection Add(IniProperty property) { string key = property.Key; IniType type = property.Type; /* Generate a key for certain types, this fixes the problem * with duplicate key for non-property lines. */ switch (type) { case IniType.Comment: case IniType.EmptyLine: case IniType.Invalid: // Empty key means we have to generate a random one if (string.IsNullOrEmpty(key)) { key = GenerateKey(type); } break; case IniType.Property: default: key = property.Key; break; } // Apply new key and section property.Key = key; property.Section = this.Name; this.properties.Add(key, property); return(this); }
/// <include file='IniItem.xml' path='//Constructor[@name="Constructor"]/docs/*' /> internal protected IniItem (string name, string value, IniType type, string comment) { iniName = name; iniValue = value; iniType = type; iniComment = comment; }
/// <summary> /// Resets all of the current INI line data. /// </summary> private void Reset() { this.name.Remove(0, this.name.Length); this.value.Remove(0, this.value.Length); this.comment.Remove(0, this.comment.Length); iniType = IniType.Empty; hasComment = false; }
/// <summary> /// Resets all of the current INI line data. /// </summary> private void Reset() { name.Remove(0, name.Length); value.Remove(0, value.Length); comment.Remove(0, comment.Length); iniType = IniType.Empty; hasComment = false; }
/// <include file='IniItem.xml' path='//Constructor[@name="Constructor"]/docs/*' /> internal protected IniItem (string name, string value, IniType type, string comment, bool RemoveQuotes) { if (value != null && RemoveQuotes && value.Contains("\"")) { value = value.Replace("\"", ""); NeedsQuotes = true; } iniName = name; iniValue = value; iniType = type; iniComment = comment; }
/// <include file='IniItem.xml' path='//Constructor[@name="Constructor"]/docs/*' /> internal protected IniItem(string name, string value, IniType type, string comment, bool RemoveQuotes) { if (value != null && RemoveQuotes && value.Contains("\"")) { value = value.Replace("\"", ""); NeedsQuotes = true; } iniName = name; iniValue = value; iniType = type; iniComment = comment; }
/// <summary> /// Adds an IniProperty to the end of the properties list. /// </summary> /// <param name="type">The type of the property.</param> /// <param name="value">The value of the property.</param> public IniSection Add(IniType type, string value) { if (type == IniType.Property) { // Properties can't have empty key. throw new ArgumentException("INI property can't have empty key."); } this.Add(new IniProperty(this.Name, type, value)); return(this); }
/// <summary> /// Reads the next INI line item. /// </summary> private bool ReadNext() { bool result = true; int ch = PeekChar(); Reset(); if (IsComment(ch)) { iniType = IniType.Empty; ReadChar(); // consume comment character ReadComment(); return(result); } switch (ch) { case ' ': case '\t': case '\r': SkipWhitespace(); ReadNext(); break; case '\n': ReadChar(); break; case '[': ReadSection(); break; case -1: readState = IniReadState.EndOfFile; result = false; break; default: ReadKey(); break; } return(result); }
/// <summary> /// Reads a key. /// </summary> private void ReadKey() { int ch = -1; iniType = IniType.Key; while (true) { ch = PeekChar(); if (ch == '=') // or ':' { ReadChar(); break; } if (EndOfLine(ch)) { throw new IniException(this, "Expected '='"); } this.name.Append((char)ReadChar()); } ReadKeyValue(); SearchForComment(); RemoveTrailingWhitespace(this.name); if (keyList.Contains(this.name.ToString())) { throw new IniException(this, "Key found [" + this.name.ToString() + "] with identical name in same section"); } else { keyList.Add(this.name.ToString(), null); } }
/// <summary> /// Reads an INI section. /// </summary> private void ReadSection() { int ch = -1; iniType = IniType.Section; ch = ReadChar(); keyList.Clear(); while (true) { ch = PeekChar(); if (ch == ']') { break; } if (EndOfLine(ch)) { throw new IniException(this, "Expected ']'"); } this.name.Append((char)ReadChar()); } SearchForComment(); RemoveTrailingWhitespace(this.name); if (sectionList.Contains(this.name.ToString())) { throw new IniException(this, "Section found with identical name"); } else { sectionList.Add(this.name.ToString(), null); } }
/// <summary> /// Reads an INI section. /// </summary> private void ReadSection() { int ch = -1; iniType = IniType.Section; ch = ReadChar (); // consume "[" while (true) { ch = PeekChar (); if (ch == ']') { break; } if (EndOfLine (ch)) { throw new IniException (this, "Expected section end (])"); } this.name.Append ((char)ReadChar ()); } ConsumeToEnd (); // all after '[' is garbage RemoveTrailingWhitespace (this.name); }
/// <summary> /// Resets all of the current INI line data. /// </summary> private void Reset() { this.name.Remove (0, this.name.Length); this.value.Remove (0, this.value.Length); this.comment.Remove (0, this.comment.Length); iniType = IniType.Empty; hasComment = false; }
/// <summary> /// Reads a key. /// </summary> private void ReadKey() { int ch = -1; iniType = IniType.Key; while (true) { ch = PeekChar (); if (IsAssign (ch)) { ReadChar (); break; } if (EndOfLine (ch)) { if (acceptNoAssignmentOperator) { break; } throw new IniException (this, String.Format ("Expected assignment operator ({0})", assignDelimiters[0])); } this.name.Append ((char)ReadChar ()); } ReadKeyValue (); SearchForComment (); RemoveTrailingWhitespace (this.name); }
/// <summary> /// Reads the next INI line item. /// </summary> private bool ReadNext() { bool result = true; int ch = PeekChar (); Reset (); if (IsComment (ch)) { iniType = IniType.Empty; ReadChar (); // consume comment character ReadComment (); return result; } switch (ch) { case ' ': case '\t': case '\r': SkipWhitespace (); ReadNext (); break; case '\n': ReadChar (); break; case '[': ReadSection (); break; case -1: readState = IniReadState.EndOfFile; result = false; break; default: ReadKey (); break; } return result; }
/// <summary> /// Reads an INI section. /// </summary> private void ReadSection() { int ch = -1; iniType = IniType.Section; ch = ReadChar (); // consume "[" keyList.Clear (); while (true) { ch = PeekChar (); if (ch == ']') { break; } if (EndOfLine (ch)) { throw new IniException (this, "Expected ']'"); } this.name.Append ((char)ReadChar ()); } SearchForComment (); RemoveTrailingWhitespace (this.name); if (sectionList.Contains (this.name.ToString ())) { throw new IniException (this, "Section found with identical name"); } else { sectionList.Add (this.name.ToString (), null); } }
/// <summary> /// Adds an IniProperty to the end of the properties list. /// </summary> /// <param name="type">The type of the property.</param> /// <param name="value">The value of the property.</param> public IniSection Add(IniType type, string value) { if (type == IniType.Property) { // Properties can't have empty key. throw new ArgumentException("INI property can't have empty key."); } this.Add(new IniProperty(this.Name, type, value)); return this; }
/// <summary> /// Reads a key. /// </summary> private void ReadKey() { int ch = -1; iniType = IniType.Key; while (true) { ch = PeekChar (); if (ch == '=') { // or ':' ReadChar (); break; } if (EndOfLine (ch)) { throw new IniException (this, "Expected '='"); } this.name.Append ((char)ReadChar ()); } ReadKeyValue (); SearchForComment (); RemoveTrailingWhitespace (this.name); if (keyList.Contains (this.name.ToString ())) { throw new IniException (this, "Key found [" + this.name.ToString () + "] with identical name in same section"); } else { keyList.Add (this.name.ToString (), null); } }
/// <summary> /// Generates and returns a random key by combining the type name + a random number. /// </summary> private string GenerateKey(IniType type) { if (type == IniType.Property) throw new ArgumentException("Can't generate key for properties.", "type"); string key = string.Empty; int attempts = 0; // Keep generating a new key until it finds a unused one. // This shouldn't add much delay, if any, unless the INI file is absolutely MASSIVE. do { key = type.ToString() + random.Next(int.MaxValue); if ((attempts++) >= int.MaxValue) { // There is literally no keys left throw new Exception("No random key available."); } } while (this.properties.Contains(key)); return key; }
/// <summary>Writes the stage ini.</summary> /// <param name="_initData">設定ファイルに書き込む値</param> /// <see cref="WriteStageIni" /> public void WriteStageIni(IniType _initData) { string val; try { // エンコーダの分解能の書き込み val = String.Format(initData.EncoderResolution.X.ToString(), "0.0000"); WritePrivateProfileString("ENCODER", "ENCX", val, @path); val = String.Format(initData.EncoderResolution.Y.ToString(), "0.0000"); WritePrivateProfileString("ENCODER", "ENCY", val, @path); val = String.Format(initData.EncoderResolution.Z.ToString(), "0.0000"); WritePrivateProfileString("ENCODER", "ENCZ", val, @path); // リミットスイッチの極性 val = Convert.ToString(initData.LimitPol, 16); WritePrivateProfileString("LIMIT", "POL", val, @path); // モータ分解能の書き込み val = String.Format(initData.MotorResolution.X.ToString(), "0.000000"); WritePrivateProfileString("MOTOR", "RESOLVX", val, @path); val = String.Format(initData.MotorResolution.Y.ToString(), "0.000000"); WritePrivateProfileString("MOTOR", "RESOLVY", val, @path); val = String.Format(initData.MotorResolution.Z.ToString(), "0.000000"); WritePrivateProfileString("MOTOR", "RESOLVZ", val, @path); val = String.Format(initData.MotorInitialVelocity.X.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "V0X", val, @path); val = String.Format(initData.MotorInitialVelocity.Y.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "V0Y", val, @path); val = String.Format(initData.MotorInitialVelocity.Z.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "V0Z", val, @path); val = String.Format(initData.MotorAccelTime.X.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "ATX", val, @path); val = String.Format(initData.MotorAccelTime.Y.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "ATY", val, @path); val = String.Format(initData.MotorAccelTime.Z.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "ATZ", val, @path); val = String.Format(initData.MotorSpeed1.X.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED1X", val, @path); val = String.Format(initData.MotorSpeed1.Y.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED1Y", val, @path); val = String.Format(initData.MotorSpeed1.Z.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED1Z", val, @path); val = String.Format(initData.MotorSpeed2.X.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED2X", val, @path); val = String.Format(initData.MotorSpeed2.Y.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED2Y", val, @path); val = String.Format(initData.MotorSpeed2.Z.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED2Z", val, @path); val = String.Format(initData.MotorSpeed3.X.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED3X", val, @path); val = String.Format(initData.MotorSpeed3.Y.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED3Y", val, @path); val = String.Format(initData.MotorSpeed3.Z.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED3Z", val, @path); val = String.Format(initData.MotorSpeed4.X.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED4X", val, @path); val = String.Format(initData.MotorSpeed4.Y.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED4Y", val, @path); val = String.Format(initData.MotorSpeed4.Z.ToString(), "0.0000"); WritePrivateProfileString("MOTOR", "SPEED4Z", val, @path); } catch (Exception) { System.Console.WriteLine("Error: 設定ファイルの書き込みに失敗しました."); System.Console.WriteLine("Error: Failed writing Configure File."); } }
private static void FunctionReadINI(string[] line, IniType type) { if (line.Length < 4) { Warn("Missing arguments to function ReadINI"); return; } if (line.Length > 4) Warn("Unexpected extra arguments to function ReadINI"); switch (type) { case IniType.Fallout: variables[line[1]] = (string)ExecuteMethod(() => Script.GetFalloutIniString(line[2], line[3])); break; case IniType.FalloutPrefs: variables[line[1]] = (string)ExecuteMethod(() => Script.GetPrefsIniString(line[2], line[3])); break; case IniType.Geck: variables[line[1]] = (string)ExecuteMethod(() => Script.GetGeckIniString(line[2], line[3])); break; case IniType.GeckPrefs: variables[line[1]] = (string)ExecuteMethod(() => Script.GetGeckPrefsIniString(line[2], line[3])); break; } }
private static void FunctionEditINI(string[] line, IniType type) { if (line.Length < 4) { Warn("Missing arguments to EditINI"); return; } if (line.Length > 4) Warn("Unexpected arguments to EditINI"); switch (type) { case IniType.Fallout: ExecuteMethod(() => Script.EditFalloutINI(line[1], line[2], line[3], true)); break; case IniType.FalloutPrefs: ExecuteMethod(() => Script.EditPrefsINI(line[1], line[2], line[3], true)); break; case IniType.Geck: ExecuteMethod(() => Script.EditGeckINI(line[1], line[2], line[3], true)); break; case IniType.GeckPrefs: ExecuteMethod(() => Script.EditGeckPrefsINI(line[1], line[2], line[3], true)); break; } }