lotrointerface.com
Search Downloads

LoTROInterface SVN BuildSkin

[/] [branches/] [UiBuilder-Compat/] [BuildSkin.cs] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 Mevordel-4860
using System;
2 Mevordel-4860
using System.Collections.Generic;
3 Mevordel-4860
using System.ComponentModel;
4 Mevordel-4860
using System.Data;
5 Mevordel-4860
using System.Drawing;
6 Mevordel-4860
using System.Text;
7 Mevordel-4860
using System.Windows.Forms;
8 Mevordel-4860
 
9 Mevordel-4860
namespace BuildSkin
10 Mevordel-4860
{
11 Mevordel-4860
    public partial class fBuildSkin : Form
12 Mevordel-4860
    {
13 Mevordel-4860
        public fBuildSkin()
14 Mevordel-4860
        {
15 Mevordel-4860
            InitializeComponent();
16 Mevordel-4860
            // Fill List of Elements
17 Mevordel-4860
            short iCount = 0;
18 Mevordel-4860
            foreach (Control oGroup in sHorizontal.Panel1.Controls)
19 Mevordel-4860
            {
20 Mevordel-4860
                foreach (Control oCtrl in oGroup.Controls)
21 Mevordel-4860
                {
22 Mevordel-4860
                    if (oCtrl.GetType() == typeof(ComboBox))
23 Mevordel-4860
                    {
24 Mevordel-4860
                        oAllBoxes[iCount] = ((ComboBox)oCtrl);
25 Mevordel-4860
                        iCount++;
26 Mevordel-4860
                    }
27 Mevordel-4860
                }
28 Mevordel-4860
            }
29 Mevordel-4860
            RefreshAll();
30 Mevordel-4860
            LoadOptions();
31 Mevordel-4860
        }
32 5 Mevordel-4860
        void OnClose(object oSender, FormClosingEventArgs e)
33 3 Mevordel-4860
        {
34 Mevordel-4860
            SaveOptions();
35 Mevordel-4860
        }
36 5 Mevordel-4860
        void LoadSkin(object oSender, EventArgs e)
37 3 Mevordel-4860
        {
38 Mevordel-4860
            LoadSkin(tSkinName.Text);
39 Mevordel-4860
        }
40 5 Mevordel-4860
        void LoadSkin(string sName)
41 3 Mevordel-4860
        {
42 Mevordel-4860
            //Load From file
43 Mevordel-4860
            if (System.IO.File.Exists(sName + " Skin\\SkinDefinition.BuildSkin"))
44 Mevordel-4860
            {
45 Mevordel-4860
                string[] sElements = System.IO.File.ReadAllLines(sName + " Skin\\SkinDefinition.BuildSkin"); //Same order as oAllBoxes (+ 2 for resolutions)
46 Mevordel-4860
 
47 Mevordel-4860
                //Load Resolution
48 Mevordel-4860
                if (oResolutionMain.Items.Contains(sElements[0]))
49 Mevordel-4860
                {
50 Mevordel-4860
                    oResolutionMain.SelectedIndex = oResolutionMain.Items.IndexOf(sElements[0]);
51 Mevordel-4860
                }
52 5 Mevordel-4860
                else
53 Mevordel-4860
                {
54 Mevordel-4860
                    ErrorMessage(2);
55 Mevordel-4860
                }
56 3 Mevordel-4860
                if (oResolutionToolbar.Items.Contains(sElements[1]))
57 Mevordel-4860
                {
58 Mevordel-4860
                    oResolutionToolbar.SelectedIndex = oResolutionToolbar.Items.IndexOf(sElements[1]);
59 Mevordel-4860
                }
60 5 Mevordel-4860
                else
61 Mevordel-4860
                {
62 Mevordel-4860
                    ErrorMessage(2);
63 Mevordel-4860
                }
64 3 Mevordel-4860
 
65 Mevordel-4860
                //Fill in ComboBoxes
66 Mevordel-4860
                //Must use for to preserve order, offset 2 for resolution lines
67 Mevordel-4860
                for (short i = 2; i < sElements.Length; i++)
68 Mevordel-4860
                {
69 Mevordel-4860
                    string[] sTmp = sElements[i].Split('=');
70 Mevordel-4860
                    foreach (ComboBox oCurrBox in oAllBoxes)
71 Mevordel-4860
                    {
72 Mevordel-4860
                        if (((String)oCurrBox.Tag) == sTmp[0])
73 Mevordel-4860
                        {
74 Mevordel-4860
                            if (oCurrBox.Items.Contains(sTmp[1]))
75 Mevordel-4860
                            {
76 Mevordel-4860
                                oCurrBox.SelectedIndex = oCurrBox.Items.IndexOf(sTmp[1]);
77 Mevordel-4860
                            }
78 Mevordel-4860
                            else
79 Mevordel-4860
                            {
80 Mevordel-4860
                                oCurrBox.SelectedIndex = oCurrBox.Items.IndexOf("Default");
81 Mevordel-4860
                            }
82 5 Mevordel-4860
                            break;
83 3 Mevordel-4860
                        }
84 Mevordel-4860
                    }
85 Mevordel-4860
                }
86 Mevordel-4860
            }
87 Mevordel-4860
            else
88 Mevordel-4860
            {
89 Mevordel-4860
                ErrorMessage(0);
90 Mevordel-4860
                return;
91 Mevordel-4860
            }
92 Mevordel-4860
        }
93 5 Mevordel-4860
        void BuildSkin(object oSender, EventArgs e)
94 3 Mevordel-4860
        {
95 Mevordel-4860
            //Open (Create/Overwrite) Files for writing
96 5 Mevordel-4860
            try
97 Mevordel-4860
            {
98 Mevordel-4860
                System.IO.Directory.CreateDirectory(tSkinName.Text + " Skin\\");
99 Mevordel-4860
            }
100 Mevordel-4860
            catch
101 Mevordel-4860
            {
102 Mevordel-4860
                ErrorMessage(3);
103 Mevordel-4860
            }
104 3 Mevordel-4860
 
105 5 Mevordel-4860
            try
106 Mevordel-4860
            {
107 Mevordel-4860
                System.IO.StreamWriter fXMLFile = new System.IO.StreamWriter(tSkinName.Text + " Skin\\SkinDefinition.xml", false);
108 Mevordel-4860
                System.IO.StreamWriter fConfFile = new System.IO.StreamWriter(tSkinName.Text + " Skin\\SkinDefinition.BuildSkin", false);
109 3 Mevordel-4860
 
110 5 Mevordel-4860
                //Save resolution
111 Mevordel-4860
                fConfFile.WriteLine(oResolutionMain.Text);
112 Mevordel-4860
                fConfFile.WriteLine(oResolutionToolbar.Text);
113 3 Mevordel-4860
 
114 5 Mevordel-4860
                //XML Header
115 Mevordel-4860
                fXMLFile.WriteLine("<opt><SkinName Name=\"" + tSkinName.Text + "\" />");
116 Mevordel-4860
 
117 Mevordel-4860
                //Write content to files
118 Mevordel-4860
                //Use for to preserve order
119 Mevordel-4860
                foreach (ComboBox oCurrBox in oAllBoxes)
120 3 Mevordel-4860
                {
121 5 Mevordel-4860
                    fConfFile.WriteLine(oCurrBox.Tag + "=" + oCurrBox.Text);
122 Mevordel-4860
                    if (oCurrBox.Text == "Default" && ! Options.ExplicitDefaults) { continue; }
123 Mevordel-4860
                    if (System.IO.File.Exists(oCurrBox.Tag + "\\" + oCurrBox.Text + ".xml"))
124 3 Mevordel-4860
                    {
125 5 Mevordel-4860
                        if (System.IO.File.Exists(oCurrBox.Tag + "\\" + oCurrBox.Text + "res\\resenable.xml"))
126 3 Mevordel-4860
                        {
127 5 Mevordel-4860
                            if (((String)oCurrBox.Tag) == "Toolbar")
128 Mevordel-4860
                            {
129 Mevordel-4860
                                fXMLFile.WriteLine(System.IO.File.ReadAllText(oCurrBox.Tag + "\\" + oCurrBox.Text + "res\\" + oCurrBox.Text + " " + oResolutionToolbar.Text + ".xml"));
130 Mevordel-4860
                            }
131 Mevordel-4860
                            else
132 Mevordel-4860
                            {
133 Mevordel-4860
                                fXMLFile.WriteLine(System.IO.File.ReadAllText(oCurrBox.Tag + "\\" + oCurrBox.Text + "res\\" + oCurrBox.Text + " " + oResolutionMain.Text + ".xml"));
134 Mevordel-4860
                            }
135 3 Mevordel-4860
                        }
136 Mevordel-4860
                        else
137 Mevordel-4860
                        {
138 5 Mevordel-4860
                            fXMLFile.WriteLine(System.IO.File.ReadAllText(oCurrBox.Tag + "\\" + oCurrBox.Text + ".xml"));
139 3 Mevordel-4860
                        }
140 Mevordel-4860
                    }
141 Mevordel-4860
                    else
142 Mevordel-4860
                    {
143 10 Mevordel-4860
                        if (oCurrBox.Text != "")
144 Mevordel-4860
                        {
145 Mevordel-4860
                            ErrorMessage(5);
146 Mevordel-4860
                        }
147 3 Mevordel-4860
                    }
148 Mevordel-4860
                }
149 Mevordel-4860
 
150 5 Mevordel-4860
                //XML Footer
151 Mevordel-4860
                fXMLFile.WriteLine("</opt> <!-- Built by BuildSkin -->");
152 3 Mevordel-4860
 
153 5 Mevordel-4860
                //Close Files
154 Mevordel-4860
                fConfFile.Close();
155 Mevordel-4860
                fXMLFile.Close();
156 Mevordel-4860
            }
157 Mevordel-4860
            catch
158 Mevordel-4860
            {
159 Mevordel-4860
                ErrorMessage(4);
160 Mevordel-4860
            }
161 3 Mevordel-4860
 
162 Mevordel-4860
            MessageBox.Show("Skin " + tSkinName.Text + " successfully built/updated.");
163 Mevordel-4860
        }
164 5 Mevordel-4860
        void EditSkin(object oSender, EventArgs e)
165 3 Mevordel-4860
        {
166 Mevordel-4860
            if (System.IO.File.Exists(tSkinName.Text + " Skin\\SkinDefinition.xml") && System.IO.File.Exists(Options.EditorPath))
167 Mevordel-4860
            {
168 Mevordel-4860
                System.Diagnostics.Process procEditor = new System.Diagnostics.Process();
169 Mevordel-4860
                procEditor.StartInfo = new System.Diagnostics.ProcessStartInfo(Options.EditorPath, "\"" + tSkinName.Text + " Skin\\SkinDefinition.xml\"");
170 Mevordel-4860
                procEditor.Start();
171 Mevordel-4860
            }
172 Mevordel-4860
            else
173 Mevordel-4860
            {
174 5 Mevordel-4860
                ErrorMessage(1);
175 3 Mevordel-4860
            }
176 Mevordel-4860
        }
177 5 Mevordel-4860
        void DeleteSkin(object oSender, EventArgs e)
178 3 Mevordel-4860
        {
179 5 Mevordel-4860
            try
180 3 Mevordel-4860
            {
181 5 Mevordel-4860
                if (System.IO.File.Exists(tSkinName.Text + " Skin\\SkinDefinition.xml"))
182 Mevordel-4860
                {
183 Mevordel-4860
                    System.IO.File.Delete(tSkinName.Text + " Skin\\SkinDefinition.xml");
184 Mevordel-4860
                }
185 Mevordel-4860
                if (System.IO.File.Exists(tSkinName.Text + " Skin\\SkinDefinition.BuildSkin"))
186 Mevordel-4860
                {
187 Mevordel-4860
                    System.IO.File.Delete(tSkinName.Text + " Skin\\SkinDefinition.BuildSkin");
188 Mevordel-4860
                }
189 Mevordel-4860
                if (System.IO.Directory.Exists(tSkinName.Text + " Skin"))
190 Mevordel-4860
                {
191 Mevordel-4860
                    System.IO.Directory.Delete(tSkinName.Text + " Skin");
192 Mevordel-4860
                }
193 Mevordel-4860
 
194 Mevordel-4860
                MessageBox.Show("Skin " + tSkinName.Text + " deleted.");
195 3 Mevordel-4860
            }
196 5 Mevordel-4860
            catch
197 3 Mevordel-4860
            {
198 5 Mevordel-4860
                ErrorMessage(6);
199 3 Mevordel-4860
            }
200 Mevordel-4860
        }
201 5 Mevordel-4860
        void Preview(object oSender, EventArgs e)
202 3 Mevordel-4860
        {
203 Mevordel-4860
            pPreview.ImageLocation = ((ComboBox)oSender).Tag.ToString() + "\\Preview\\" + ((ComboBox)oSender).SelectedItem.ToString() + ".jpg";
204 Mevordel-4860
        }
205 5 Mevordel-4860
        void LoadOptions()
206 3 Mevordel-4860
        {
207 Mevordel-4860
            //Read From File to Variables
208 Mevordel-4860
            if (System.IO.File.Exists(".\\BuildSkin.conf"))
209 Mevordel-4860
            {
210 5 Mevordel-4860
                try
211 Mevordel-4860
                {
212 Mevordel-4860
                    string[] oFileContents = System.IO.File.ReadAllLines(".\\BuildSkin.conf");
213 Mevordel-4860
                    Options.EditorPath = oFileContents[0];
214 Mevordel-4860
                    Options.LastSkin = oFileContents[1];
215 Mevordel-4860
                    Options.AvailRes = oFileContents[2].Split(',');
216 Mevordel-4860
                    Options.AvailToolbarRes = oFileContents[3].Split(',');
217 Mevordel-4860
                    Options.ExplicitDefaults = (oFileContents[4].ToLowerInvariant() == "true");
218 Mevordel-4860
                    Options.AutoLoadLast = (oFileContents[5].ToLowerInvariant() == "true");
219 Mevordel-4860
                }
220 Mevordel-4860
                catch { ErrorMessage(7); }
221 3 Mevordel-4860
            }
222 Mevordel-4860
            else //Load Defaults
223 Mevordel-4860
            {
224 Mevordel-4860
                Options.EditorPath = "C:\\Windows\\Notepad.exe";
225 Mevordel-4860
                Options.LastSkin = null;
226 Mevordel-4860
                Options.AvailRes = new string[] { "800x600", "1024x768", "1152x768", "1280x720", "1280x1024", "1366x768", "1440x900", "1600x900", "1680x1024", "1680x1050", "1920x1080", "1920x1200", "2048x1080", "2048x1536", "2560x1600", "2560x2048" };
227 Mevordel-4860
                Options.AvailToolbarRes = new string[] { "800", "1024", "1152", "1280", "1366", "1440", "1600", "1680", "1920", "2048", "2560" };
228 Mevordel-4860
                Options.ExplicitDefaults = false;
229 Mevordel-4860
                Options.AutoLoadLast = true;
230 Mevordel-4860
            }
231 Mevordel-4860
 
232 Mevordel-4860
            //Apply
233 Mevordel-4860
            oResolutionMain.Items.AddRange(Options.AvailRes);
234 Mevordel-4860
            oResolutionToolbar.Items.AddRange(Options.AvailToolbarRes);
235 Mevordel-4860
            tSkinName.Text = Options.LastSkin;
236 Mevordel-4860
            if (Options.AutoLoadLast && Options.LastSkin != null) { LoadSkin(Options.LastSkin); }
237 Mevordel-4860
        }
238 5 Mevordel-4860
        void SaveOptions()
239 3 Mevordel-4860
        {
240 Mevordel-4860
            //Set Vars
241 Mevordel-4860
            Options.LastSkin = tSkinName.Text;
242 Mevordel-4860
 
243 Mevordel-4860
            //Save to File
244 Mevordel-4860
            string sAvailRes = String.Join(",", Options.AvailRes);
245 Mevordel-4860
            string sAvailToolbarRes = String.Join(",", Options.AvailToolbarRes);
246 Mevordel-4860
            string[] sOptions = {
247 Mevordel-4860
                                    Options.EditorPath,
248 Mevordel-4860
                                    Options.LastSkin,
249 Mevordel-4860
                                    sAvailRes,
250 Mevordel-4860
                                    sAvailToolbarRes,
251 Mevordel-4860
                                    Options.ExplicitDefaults.ToString(),
252 Mevordel-4860
                                    Options.AutoLoadLast.ToString()
253 Mevordel-4860
                                };
254 5 Mevordel-4860
            try { System.IO.File.WriteAllLines("BuildSkin.conf", sOptions); }
255 Mevordel-4860
            catch { ErrorMessage(7); }
256 3 Mevordel-4860
        }
257 5 Mevordel-4860
        void ErrorMessage(int iType)
258 3 Mevordel-4860
        {
259 5 Mevordel-4860
            switch (iType)
260 Mevordel-4860
            {
261 Mevordel-4860
                case 0:
262 Mevordel-4860
                    MessageBox.Show("Missing SkinDefinition.BuildSkin");
263 Mevordel-4860
                    break;
264 Mevordel-4860
                case 1:
265 Mevordel-4860
                    MessageBox.Show("Missing SkinDefinition.XML");
266 Mevordel-4860
                    break;
267 Mevordel-4860
                case 2:
268 Mevordel-4860
                    MessageBox.Show("Unsupported resolution in loaded skin. Please select another.");
269 Mevordel-4860
                    break;
270 Mevordel-4860
                case 3:
271 Mevordel-4860
                    MessageBox.Show("Error creating skin files. Check to see if they are in use.");
272 Mevordel-4860
                    break;
273 Mevordel-4860
                case 4:
274 Mevordel-4860
                    MessageBox.Show("Error writing to skin files. Check to see if they are in use.");
275 Mevordel-4860
                    break;
276 Mevordel-4860
                case 5:
277 Mevordel-4860
                    MessageBox.Show("Missing element XML snippet. Try restarting the program to refresh.");
278 Mevordel-4860
                    break;
279 Mevordel-4860
                case 6:
280 Mevordel-4860
                    MessageBox.Show("Error deleting skin.  Check to see if it is in use.");
281 Mevordel-4860
                    break;
282 Mevordel-4860
                case 7:
283 Mevordel-4860
                    MessageBox.Show("Error loading or saving options. Check to see if the file is in use.");
284 Mevordel-4860
                    break;
285 Mevordel-4860
                case 8:
286 Mevordel-4860
                    MessageBox.Show("Error opening webpage.");
287 Mevordel-4860
                    break;
288 Mevordel-4860
                default:
289 Mevordel-4860
                    MessageBox.Show("An unkown error has occurred.");
290 Mevordel-4860
                    break;
291 Mevordel-4860
            }
292 3 Mevordel-4860
        }
293 5 Mevordel-4860
        void RefreshAll()
294 3 Mevordel-4860
        {
295 Mevordel-4860
            //Refresh Elements
296 Mevordel-4860
            foreach (ComboBox oCurrBox in oAllBoxes)
297 Mevordel-4860
            {
298 Mevordel-4860
                if (System.IO.Directory.Exists(((string)oCurrBox.Tag)))
299 Mevordel-4860
                {
300 Mevordel-4860
                    foreach (string sFile in System.IO.Directory.GetFiles(((string)oCurrBox.Tag), "*.xml"))
301 Mevordel-4860
                    {
302 Mevordel-4860
                        oCurrBox.Items.Add(System.IO.Path.GetFileNameWithoutExtension(sFile));
303 Mevordel-4860
                    }
304 Mevordel-4860
                    if (oCurrBox.Items.Count > 1) { oCurrBox.Enabled = true; }
305 Mevordel-4860
                }
306 Mevordel-4860
            }
307 Mevordel-4860
 
308 Mevordel-4860
            //Refresh Skins
309 Mevordel-4860
            foreach (string sDir in System.IO.Directory.GetDirectories(".", "* Skin"))
310 Mevordel-4860
            {
311 Mevordel-4860
                tSkinName.Items.Add(sDir.Remove(sDir.Length - 5).Remove(0,2));
312 Mevordel-4860
            }
313 Mevordel-4860
        }
314 5 Mevordel-4860
        void OptionsWindow(object oSender, EventArgs e)
315 3 Mevordel-4860
        {
316 5 Mevordel-4860
            if (MessageBox.Show("This feature is not yet implemented. Please edit the configuration file manually.", "Options") == DialogResult.OK)
317 Mevordel-4860
            {
318 Mevordel-4860
                //Change Options
319 Mevordel-4860
 
320 Mevordel-4860
            }
321 3 Mevordel-4860
        }
322 5 Mevordel-4860
        void NavigateToLI(object oSender, LinkLabelLinkClickedEventArgs e)
323 3 Mevordel-4860
        {
324 5 Mevordel-4860
            try { System.Diagnostics.Process.Start("http://www.lotrointerface.com/downloads/info623-BuildSkin.html"); }
325 Mevordel-4860
            catch { ErrorMessage(8); }
326 3 Mevordel-4860
        }
327 5 Mevordel-4860
        struct Options
328 3 Mevordel-4860
        {
329 Mevordel-4860
            public static string EditorPath;
330 Mevordel-4860
            public static string LastSkin;
331 Mevordel-4860
            public static string[] AvailRes;
332 Mevordel-4860
            public static string[] AvailToolbarRes;
333 Mevordel-4860
            public static bool ExplicitDefaults;
334 Mevordel-4860
            public static bool AutoLoadLast;
335 Mevordel-4860
        }
336 5 Mevordel-4860
        static ComboBox[] oAllBoxes = new ComboBox[74];
337 3 Mevordel-4860
    }
338 Mevordel-4860
}

All times are GMT -5. The time now is 11:15 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui