Ejemplo n.º 1
0
        private void btnLoadEnumOptions_Click(object sender, EventArgs e)
        {
            //Prepare OpenFileDialog parameters
            openFileDialog1.InitialDirectory = Properties.Settings.Default.MarlinDirectory;
            openFileDialog1.Filter           = "h files (*.h)|*.h";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.FileName         = "";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Get the path of specified file
                string filePath = openFileDialog1.FileName;

                //Allitems will have all #defines in choosen .h file
                cMarlinSettings AllItems = new cMarlinSettings();

                //LoadedEnumOptions will have only the integer #defines of AllItems
                //cMarlinSettings EnumOptions = new cMarlinSettings();
                LoadedEnumOptions.Clear();

                //Load #defines from .h and store in AllItems
                MarlingRWConfig.ReadConfig(AllItems, filePath);

                // Filter the integer #defines and store them in LoadedEnumOptions
                foreach (var key in AllItems.Keys)
                {
                    if (AllItems[key] is Int32)
                    {
                        LoadedEnumOptions.Add(key, (Int32)AllItems[key]);
                    }
                }
                FillListBoxLoadedOptions();
            }
        }
Ejemplo n.º 2
0
 public void WriteSettings(cMarlinSettings MSetting, XmlWriter writer)
 {
     foreach (var key in MSetting.Keys)
     {
         if (MSetting[key] is cMarlinSettings)
         {
             writer.WriteStartElement("Setting");
             writer.WriteAttributeString("Title", (MSetting[key] as cMarlinSettings).Title);
             writer.WriteAttributeString("Type", "Group");
             WriteSettings((MSetting[key] as cMarlinSettings), writer);
             writer.WriteEndElement();
         }
         else
         {
             writer.WriteStartElement("Setting");
             writer.WriteAttributeString("Title", key.ToString());
             string EntryTypeStr = MSetting[key].GetType().ToString();
             writer.WriteAttributeString("Type", EntryTypeStr);
             writer.WriteAttributeString("Value", MSetting[key].ToString());
             writer.WriteEndElement();
         }
     }
 }
Ejemplo n.º 3
0
        static public void ReadConfig(cMarlinSettings MarlingSettings, string PathFile)
        {
            try
            {   //"D:\Marlin-2.0.7.2\Marlin\Configuration.h"
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(PathFile))
                {
                    string   DefineStr = "#define";
                    string[] DefineParams;
                    string   line;

                    // Read and display lines from the file until the end of
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        bool LineComment = false;
                        line.Trim();
                        if (line.IndexOf("//") == 0)
                        {
                            LineComment = true;
                        }
                        int DefinePos = line.IndexOf("#define");
                        if (DefinePos > -1)  // #define was found
                        {
                            string DefineContentStr = line.Substring(DefinePos + DefineStr.Length + 1);
                            DefineParams = System.Text.RegularExpressions.Regex.Split(DefineContentStr, @"\s+");
                            int ParamCount = 0;
                            foreach (string Param in DefineParams)
                            {
                                if (Param.IndexOf("//") == 0)
                                {
                                    break;
                                }
                                else
                                {
                                    ParamCount++;
                                }
                            }
                            //DefineContentStr.Split(' ');
                            //if (DefineParams.Length == 1)
                            if (ParamCount == 1)
                            {
                                MarlingSettings.Add(DefineParams[0], !LineComment);
                            }
                            if (ParamCount == 2)
                            {
                                Double ParamDouble;
                                Int32  ParamInt;
                                if (Int32.TryParse(DefineParams[1], out ParamInt))
                                {
                                    MarlingSettings.Add(DefineParams[0], ParamInt);
                                }
                                else
                                if (double.TryParse(DefineParams[1], out ParamDouble))
                                {
                                    MarlingSettings.Add(DefineParams[0], ParamDouble);
                                }
                                else
                                {
                                    MarlingSettings.Add(DefineParams[0], DefineParams[1]);
                                }
                            }
                        }

                        Console.WriteLine(line);
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }