Esempio n. 1
0
        public bool PutFile(MOG_Ini iniFile)
        {
            string section, key, value;

            // Loop through all the sections and keys and add them to our ini
            for (int x = 0; x < iniFile.CountSections(); x++)
            {
                section = iniFile.GetSectionByIndex(x);

                if (iniFile.CountKeys(section) != 0)
                {
                    for (int y = 0; y < iniFile.CountKeys(section); y++)
                    {
                        key   = iniFile.GetKeyNameByIndex(section, y);
                        value = iniFile.GetKeyByIndex(section, y);

                        PutString(section, key, value);
                    }
                }
                else
                {
                    // Add the section with no keys into our ini
                    PutSectionString(section, "");
                }
            }

            return(true);
        }
Esempio n. 2
0
        public bool InitializeMogRepository()
        {
            // FIRST check if we have a valid repository saved in our loader file
            // Load system Ini
            MOG_Ini loader = new MOG_Ini(LoaderConfigFile);

            if (loader != null && loader.CountSections() > 0)
            {
                if (loader.SectionExist("Loader"))
                {
                    if (loader.KeyExist("Loader", "SystemRepositoryPath"))
                    {
                        // Lets verify if the repository that was saved is really still a repository?
                        if (Directory.Exists(loader.GetString("Loader", "SystemRepositoryPath") + "\\Tools") &&
                            Directory.Exists(loader.GetString("Loader", "SystemRepositoryPath") + "\\ProjectTemplates") &&
                            Directory.Exists(loader.GetString("Loader", "SystemRepositoryPath") + "\\Updates"))
                        {
                            mRepositoryPath = loader.GetString("Loader", "SystemRepositoryPath");

                            // SECOND make sure that we have the mog.ini saved correctly in the current directory
                            if (File.Exists(Environment.CurrentDirectory + "\\" + LoaderTargetDirectory + "\\MOG.ini"))
                            {
                                // Also make sure it has a valid repository
                                MOG_Ini targetLoader = new MOG_Ini(Environment.CurrentDirectory + "\\" + LoaderTargetDirectory + "\\MOG.ini");
                                if (targetLoader != null && targetLoader.CountSections() > 0)
                                {
                                    if (targetLoader.SectionExist("MOG"))
                                    {
                                        if (targetLoader.KeyExist("MOG", "SystemRepositoryPath"))
                                        {
                                            // Lets verify if the repository that was saved is really still a repository?
                                            if (Directory.Exists(targetLoader.GetString("MOG", "SystemRepositoryPath") + "\\Tools") &&
                                                Directory.Exists(targetLoader.GetString("MOG", "SystemRepositoryPath") + "\\ProjectTemplates") &&
                                                Directory.Exists(targetLoader.GetString("MOG", "SystemRepositoryPath") + "\\Updates"))
                                            {
                                                return(true);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // If any of the above conditions fail, have the user locate our repository path for us
            MogForm_RepositoryBrowser_ClientLoader form = new MogForm_RepositoryBrowser_ClientLoader();

LocateRepository:
            try
            {
                mSplash.Opacity  = 0;
                this.WindowState = FormWindowState.Minimized;
                this.Opacity     = 1;
                if (form.ShowDialog() == DialogResult.OK)
                {
                    // Determine if the path selected is valid
                    if (!File.Exists(form.MOGSelectedRepository + "\\MogRepository.ini"))
                    {
                        MessageBox.Show(this, "The selected path is not a valid MOG repository.", "Invalid repository");
                        goto LocateRepository;
                    }
                    else
                    {
                        // Load the MogRepository.ini file found at the location specified by the user
                        MOG_Ini repository = new MOG_Ini(form.MOGSelectedRepository + "\\MogRepository.ini");

                        // Does this MogRepository have at least one valid repository path
                        if (repository.SectionExist("Mog_Repositories"))
                        {
                            // If there is only one specified repository, choose that one
                            if (repository.CountKeys("Mog_Repositories") == 1)
                            {
                                // Get the section
                                string section = repository.GetKeyNameByIndexSLOW("Mog_Repositories", 0);

                                // Get the path from that section
                                if (repository.SectionExist(section) && repository.KeyExist(section, "SystemRepositoryPath"))
                                {
                                    mRepositoryPath = repository.GetString(section, "SystemRepositoryPath");
                                }
                                else
                                {
                                    MessageBox.Show(this, "The selected path does not have or is missing a repository path.", "Invalid repository");
                                    goto LocateRepository;
                                }
                            }
                            else if (repository.CountKeys("Mog_Repositories") > 1)
                            {
                                // The user must now choose which repository to use
                                MogForm_MultiRepository multiRep = new MogForm_MultiRepository();
                                for (int i = 0; i < repository.CountKeys("Mog_Repositories"); i++)
                                {
                                    multiRep.RepositoryComboBox.Items.Add(repository.GetKeyNameByIndexSLOW("Mog_Repositories", i));
                                }
                                multiRep.RepositoryComboBox.SelectedIndex = 0;

                                // Show the form to the user and have him select between the repository sections found
                                if (multiRep.ShowDialog() == DialogResult.OK)
                                {
                                    // Get the section
                                    string userSection = multiRep.RepositoryComboBox.Text;

                                    // Get the path from that section
                                    if (repository.SectionExist(userSection) && repository.KeyExist(userSection, "SystemRepositoryPath"))
                                    {
                                        mRepositoryPath = repository.GetString(userSection, "SystemRepositoryPath");
                                    }
                                    else
                                    {
                                        MessageBox.Show(this, "The selected path does not have or is missing a repository path.", "Invalid repository");
                                        goto LocateRepository;
                                    }
                                }
                                else
                                {
                                    goto LocateRepository;
                                }
                            }
                            else
                            {
                                MessageBox.Show(this, "The selected path does not have or is missing a repository path.", "Invalid repository");
                                goto LocateRepository;
                            }
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "Invalid repository");
                goto LocateRepository;
            }


            // Double check that we got a valid mog repository path
            if (mRepositoryPath.Length == 0)
            {
                goto LocateRepository;
            }
            else
            {
                // Yup, all is well save it out
                loader.PutString("Loader", "SystemRepositoryPath", mRepositoryPath);
                loader.Save();

                // Save out our MOG.ini
                SaveMOGConfiguration();

                this.Opacity     = 0;
                mSplash.Opacity  = 1;
                this.WindowState = FormWindowState.Normal;
                return(true);
            }
        }