Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ConfigIni.cs - github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a8ca1010ef6d77f2421348b5748e0a81c80105e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace com.clusterrr.hakchi_gui
{
    public class ConfigIni
    {
        public static bool FirstRun = true;
        public static string SelectedGames = "default";
        public static string HiddenGames = "";
        public static bool CustomFlashed = false;
        public static bool UseFont = true;
        public static bool ResetHack = true;
        public static bool AutofireHack = false;
        public static bool RemoveThumbnails = false;
        public static bool EightBitPngCompression = true;
        public static bool FcStart = false;
        public static bool DisableMusic = false;
        public static byte AntiArmetLevel = 0;
        public static byte ConsoleType = 0;
        public static SelectButtonsForm.NesButtons ResetCombination = SelectButtonsForm.NesButtons.Down | SelectButtonsForm.NesButtons.Select;
        public static Dictionary<string, string> Presets = new Dictionary<string, string>();
        public static string ExtraCommandLineArguments = "";
        const string ConfigFile = "config.ini";

        public static void Load()
        {
            Debug.WriteLine("Loading config");
            var fileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), ConfigFile);
            if (File.Exists(fileName))
            {
                var configLines = File.ReadAllLines(fileName);
                string section = "";
                foreach (var line in configLines)
                {
                    var l = line.Trim();
                    if (l.StartsWith("[") && l.EndsWith("]"))
                        section = l.Substring(1, l.Length - 2).ToLower();
                    int pos = l.IndexOf('=');
                    if (pos <= 0) continue;
                    var param = l.Substring(0, pos).Trim();
                    var value = l.Substring(pos + 1).Trim();
                    switch (section)
                    {
                        case "config":
                            param = param.ToLower();
                            switch (param)
                            {
                                case "selectedgames":
                                    SelectedGames = value;
                                    break;
                                case "hiddengames":
                                    HiddenGames = value;
                                    break;
                                case "customflashed":
                                    CustomFlashed = !value.ToLower().Equals("false");
                                    FirstRun = false;
                                    break;
                                case "usefont":
                                    UseFont = !value.ToLower().Equals("false");
                                    break;
                                case "firstrun":
                                    FirstRun = !value.ToLower().Equals("false");
                                    break;
                                case "antiarmetlevel":
                                    AntiArmetLevel = byte.Parse(value);
                                    break;
                                case "resethack":
                                case "cloverconhack":
                                    ResetHack = !value.ToLower().Equals("false");
                                    break;
                                case "autofirehack":
                                    AutofireHack = !value.ToLower().Equals("false");
                                    break;
                                case "removethumbnails":
                                    RemoveThumbnails = !value.ToLower().Equals("false");
                                    break;
                                case "eightbitpngcompression":
                                    EightBitPngCompression = !value.ToLower().Equals("false");
                                    break;
                                case "resetcombination":
                                    ResetCombination = (SelectButtonsForm.NesButtons) byte.Parse(value);
                                    break;
                                case "consoletype":
                                    ConsoleType = byte.Parse(value);
                                    break;
                                case "extracommandlinearguments":
                                    ExtraCommandLineArguments = value;
                                    break;
                                case "fcstart":
                                    FcStart = !value.ToLower().Equals("false");
                                    break;
                                case "disablemusic":
                                    DisableMusic = !value.ToLower().Equals("false");
                                    break;
                            }
                            break;
                        case "presets":
                            Presets[param] = value;
                            break;
                    }
                }
            }
        }

        public static void Save()
        {
            Debug.WriteLine("Saving config");
            var configLines = new List<string>();
            configLines.Add("[Config]");
            configLines.Add(string.Format("SelectedGames={0}", SelectedGames));
            configLines.Add(string.Format("HiddenGames={0}", HiddenGames));
            configLines.Add(string.Format("CustomFlashed={0}", CustomFlashed));
            configLines.Add(string.Format("UseFont={0}", UseFont));
            configLines.Add(string.Format("ResetHack={0}", ResetHack));
            configLines.Add(string.Format("AutofireHack={0}", AutofireHack));
            configLines.Add(string.Format("FirstRun={0}", FirstRun));
            configLines.Add(string.Format("AntiArmetLevel={0}", AntiArmetLevel));
            configLines.Add(string.Format("RemoveThumbnails={0}", RemoveThumbnails));
            configLines.Add(string.Format("EightBitPngCompression={0}", EightBitPngCompression));
            configLines.Add(string.Format("ResetCombination={0}", (byte)ResetCombination));
            configLines.Add(string.Format("ConsoleType={0}", ConsoleType));
            configLines.Add(string.Format("ExtraCommandLineArguments={0}", ExtraCommandLineArguments));
            configLines.Add(string.Format("FcStart={0}", FcStart));
            configLines.Add(string.Format("DisableMusic={0}", DisableMusic));            

            configLines.Add("[Presets]");
            configLines.Add("");
            foreach (var preset in Presets.Keys)
            {
                configLines.Add(string.Format("{0}={1}", preset, Presets[preset]));
            }
            File.WriteAllLines(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), ConfigFile), configLines.ToArray());
        }
    }
}