Ejemplo n.º 1
0
        private static void ReadConfigFromFile(string path, GearDefinition gear)
        {
            var items = new List<ToolStripItem>();
            string[] pathWithFileName;

            try
            {
                pathWithFileName = Directory.GetFiles(
                        path, "*.gear", SearchOption.TopDirectoryOnly);
                string xml = File.ReadAllText(pathWithFileName[0]);
                var doc = new XmlDocument();
                doc.LoadXml(xml);

                gear.InitializeFromRootNode(doc.FirstChild);

                foreach (var child in doc.FirstChild.ChildNodes)
                {
                    XmlNode node = child as XmlNode;
                    if (node != null)
                    {
                        ToolStripMenuItem item = Parse(node);
                        if (item != null)
                            gear.MenuItems.Add(item);
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format("Unable to parse config [{0}]{1}Error: {2}", path, Environment.NewLine, ex.Message));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Trying to read configs from working directory, then from comand line arguments. 
        /// </summary>
        /// <returns></returns>
        public static GearDefinition ReadConfigs()
        {
            var gear = new GearDefinition();

            // Getting configs from command line arguments.
            var args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                gear = new GearDefinition();
                for (int i = 1; i < args.Length; i++)
                {
                    ReadConfigFromFile(args[i], gear);
                }
            }

            if (gear.MenuItems.Count == 0)
            {
                ReadConfigFromFile(Directory.GetCurrentDirectory(), gear);

                if (gear.MenuItems.Count == 0)
                {
                    MessageBox.Show(
                        "No Gear config was found. Please place config (with 'gear' extension) in target folder or pass path(s) to configs via command line args.");
                }
            }

            return gear;
        }