iniParser.Save C# (CSharp) Method

Save() public method

Save the specified file.
public Save ( IniFiles, file ) : void
file IniFiles, The file name.
return void
    public void Save(IniFiles file)
    {
        using (StreamWriter wr = new StreamWriter(Application.dataPath + "/" + file + ".ini")){
            List<string> noDup = new List<string>();
            for (int i = 0; i < subSections.Count; i++)
            {
                if (!noDup.Contains(subSections[i]))
                {
                    noDup.Add(subSections[i]);
                }
            }
            noDup.Sort();
            List<string> keysC = keys;
            List<string> valsC = vals;
            List<string> comsC = comments;
            List<string> subsC = subSections;
            for (int i = 0; i < noDup.Count; i++)
            {
                int cur = 0;
                while (subsC.Contains(noDup[i]))
                {
                    int pos = subsC.IndexOf(noDup[i]);
                    if (cur == 0)
                    {
                        if (!noDup[i].Equals(""))
                        {
                            wr.WriteLine("\n[" + noDup[i] + "]\n");
                        }
                    }
                    if (!comsC[pos].Equals(""))
                    {
                        string p1 = keysC[pos] + "=" + valsC[pos];
                        int tabs = (commentMargin - p1.Length) / 4;
                        wr.WriteLine(p1 + new string('\t', tabs) + "; " + comsC[pos]);
                    }
                    else
                    {
                        wr.WriteLine(keysC[pos] + "=" + valsC[pos]);
                    }
                    subsC.RemoveAt(pos);
                    keysC.RemoveAt(pos);
                    comsC.RemoveAt(pos);
                    valsC.RemoveAt(pos);
                    cur++;
                }
            }
        }
        Debug.Log(file+".ini Saved");
    }

Usage Example

    // Use this for initialization
    void Start()
    {
        if (mode == DisplayMode.Colors)
        {
            background = new Texture2D(1, 1);
            background.SetPixel(1, 1, colors.background);
            background.wrapMode = TextureWrapMode.Repeat;
            background.Apply();

            foreground = new Texture2D(1, 1);
            foreground.SetPixel(1, 1, colors.foreground);
            foreground.wrapMode = TextureWrapMode.Repeat;
            foreground.Apply();

            xpShadow = new Texture2D(1, 1);
            xpShadow.SetPixel(1, 1, colors.xpShadowIncrease);
            xpShadow.wrapMode = TextureWrapMode.Repeat;
            xpShadow.Apply();
        }
        else
        {
            background = textures.background;
            foreground = textures.foreground;
            xpShadow   = textures.xpShadowIncrease;
        }

        barwidth = Screen.width * screenPer;
        boxwidth = barwidth / 10;
        barstrt  = Screen.width * ((1.0f - screenPer) / 2);
        Debug.Log(barstrt + ":" + Screen.width);

        parser.Load(IniFiles.XP);
        if (parser.Get("XP").Equals(""))
        {
            parser.Set("", "XP", "0");

            float curxp = 0;

            for (int i = 0; i < 200; i++)
            {
                if (i != 0)
                {
                    curxp += 800 + (400 * (i - 1));
                }

                int cp = Mathf.CeilToInt(curxp);
                parser.Set("Ranks", "level-" + i, curxp.ToString());
            }
            curxp = 9999999;

            parser.Set("Ranks", "level-200", curxp.ToString());
            parser.Save(IniFiles.XP);
        }
        localxp = int.Parse(parser.Get("XP"));

        calc();
    }
All Usage Examples Of iniParser::Save