Ejemplo n.º 1
0
        private void ParseKSProj(string file)
        {
            if(tabControl1.TabCount != 0)
            {
                try
                {
                    SaveAll();
                    tabControl1.TabPages.Clear();
                }catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }
            if (file != null)
            {
                //Parse .ksproj file, Definition Version 0.1
                ProjFile = file;
                Version minversion;
                Version curVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                string install;
                int index;

                XmlDocument doc = new XmlDocument();
                doc.Load(file);

                //Verify that the file is within spec
                XmlNode minversionxml = doc.SelectSingleNode("/ksproj/metadata/minimumversion");
                minversion = Version.Parse(minversionxml.InnerText);
                if (curVersion >= minversion)
                {
                    //Parse settings
                    XmlNode installxml = doc.SelectSingleNode("/ksproj/settings/selectedinstall");
                    XmlNode indexxml = doc.SelectSingleNode("/ksproj/settings/selectedindex");
                    XmlNode rootxml = doc.SelectSingleNode("/ksproj/metadata/rootdir");
                    install = installxml.InnerText;
                    try
                    {
                        index = Convert.ToInt32(indexxml.InnerText.ToString());
                    }
                    catch
                    {
                        index = 0;
                    }

                    ListDirectory(rootxml.InnerText);
                    ProjRootDir = rootxml.InnerText;

                    //Parse tab data
                    XmlNodeList nodes = doc.DocumentElement.SelectNodes("/ksproj/tabs/tab");
                    List<TabRestore> tabs = new List<TabRestore>();
                    foreach (XmlNode node in nodes)
                    {
                        TabRestore tab = new TabRestore();

                        tab.index = Convert.ToInt32(node.SelectSingleNode("index").InnerText);
                        tab.title = node.SelectSingleNode("title").InnerText;
                        tab.filename = node.SelectSingleNode("file_name").InnerText;

                        tabs.Add(tab);
                    }

                    //Display the tabs
                    foreach (TabRestore tab in tabs)
                    {
                        addTab();
                        tabControl1.SelectedIndex = tab.index;
                        if (tab.title != null)
                            tabControl1.SelectedTab.Text = tab.title;
                        if (tabControl1.SelectedTab.Controls.ContainsKey("body"))
                        {
                            Scintilla body = (Scintilla)tabControl1.SelectedTab.Controls["body"];
                            try {
                                StreamReader objReader;
                                objReader = new StreamReader(tab.filename);
                                body.Text = objReader.ReadToEnd();
                                objReader.Close();
                            }
                            catch(Exception ex)
                            {
                                body.Text = "ERROR: Error opening this file. Please try again manually\r\n" + ex;   
                            }

                        }
                        if (tab.filename != null)
                            file_name[tab.index] = tab.filename;
                    }

                    //Verify the libs are available
                    //TO-DO

                    //Finish up
                    tabControl1.SelectedIndex = index;
                    toolStripComboBox1.SelectedItem = toolStripComboBox1.FindStringExact(install);
                }
                else
                    MessageBox.Show("Sorry, We cant parse this KSproj file. Current Version < Minimum Version\r\nThis probably means that this project file was created to a newer definition and doesnt backwards support this version of the parser");

            }
            else
            {
                //Welcome screen
            }
        }
Ejemplo n.º 2
0
        private void RestoreSession()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(@"KodeCache.xml");

            XmlNodeList nodes = doc.DocumentElement.SelectNodes("/Kode_Cache/Tab");

            List<TabRestore> tabs = new List<TabRestore>();

            foreach (XmlNode node in nodes)
            {
                TabRestore tab = new TabRestore();

                tab.index = Convert.ToInt32(node.SelectSingleNode("Tab_Index").InnerText);
                tab.title = node.SelectSingleNode("Tab_Title").InnerText;
                tab.text = node.SelectSingleNode("Tab_Text").InnerText;
                tab.filename = node.SelectSingleNode("Tab_File").InnerText;

                tabs.Add(tab);
            }

            foreach (TabRestore tab in tabs)
            {
                addTab();
                tabControl1.SelectedIndex = tab.index;
                if (tab.title != null)
                    tabControl1.SelectedTab.Text = tab.title;
                if (tabControl1.SelectedTab.Controls.ContainsKey("body"))
                {
                    Scintilla body = (Scintilla)tabControl1.SelectedTab.Controls["body"];
                    if (tab.title != null)
                        body.Text = tab.text;
                }
                if (tab.filename != null)
                    file_name[tab.index] = tab.filename;
            }

            tabControl1.SelectedIndex = 0;
            File.Delete("KodeCache.xml");
        }