示例#1
0
        public bool InitializeMogRepository()
        {
            // First we are going to attempt to load our loader.ini and check if a Repository path was saved froma previous load
            // 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"))
                    {
                        // Now double check that the path specified actually has a Repository.ini at that location
                        // 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") + "\\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") + "\\Updates"))
                                            {
                                                return(true);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

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

            form.ForceRepositorySelection = true;
            form.RepositoryViewVisible    = false;
            form.RepositoryViewVisible    = false;

LocateRepository:

            try
            {
                mSplash.Opacity  = 0;
                this.WindowState = FormWindowState.Minimized;
                if (form.ShowDialog() == DialogResult.OK)
                {
                    // Determine if the path selected is valid
                    if (!File.Exists(form.SelectedPath + "\\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.SelectedPath + "\\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
            {
                //Warn the user if the repository was on a local drive
                string drive = Path.GetPathRoot(mRepositoryPath);
                int    type  = (int)GetDriveType(drive);
                if (type != DRIVE_TYPE_NETWORK)
                {
                    if (MessageBox.Show(this, "It is not recommended to place a MOG Repository on a local drive because it will not be accessible to other users on the network.", "Local Drive Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        goto LocateRepository;
                    }
                }

                // 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);
            }
        }
示例#2
0
        public bool Initialize()
        {
            DisableEvents = true;
            allUpToDate   = true;

            // Is this a first run? (I.e Does MOG.Ini exist in the Current Directory?
            if (!MOGIniValid())
            {
                MogForm_RepositoryBrowser_ServerLoader reposBrowser = new MogForm_RepositoryBrowser_ServerLoader();
                reposBrowser.ForceRepositorySelection = true;
                reposBrowser.CancelButtonText         = "Exit";
                reposBrowser.RepositoryViewVisible    = false;

                bool bRepositorySelected = false;

                while (!bRepositorySelected)
                {
                    if (reposBrowser.ShowDialog() == DialogResult.OK)
                    {
                        bRepositorySelected  = true;
                        this.mRepositoryPath = reposBrowser.SelectedPath.Trim("\\".ToCharArray());

                        // extract more exact path if possible
                        if (File.Exists(this.mRepositoryPath + "\\MogRepository.ini"))
                        {
                            this.mRepositoryPath = ExtractRepositoryLocation(this.mRepositoryPath + "\\MogRepository.ini");
                        }

                        //Warn the user if the repository was on a local drive
                        string drive = Path.GetPathRoot(mRepositoryPath);
                        int    type  = (int)GetDriveType(drive);
                        if (type != DRIVE_TYPE_NETWORK)
                        {
                            if (MessageBox.Show(this, "It is not recommended to place a MOG Repository on a local drive because it will not be accessible to other users on the network.", "Local Drive Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                            {
                                //Go back and try again
                                bRepositorySelected = false;
                            }
                        }

                        if (bRepositorySelected)
                        {
                            SQLConnectForm sqlForm = new SQLConnectForm();
                            this.mConnectionString = "";
                            DialogResult result = sqlForm.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                                this.mConnectionString = sqlForm.ConnectionString;
                            }

                            // Save this MOG.ini
                            SaveMOGConfiguration();

                            // write to loader.ini
                            MOG_Ini loaderIni = new MOG_Ini(Environment.CurrentDirectory + "\\Loader.ini");
                            loaderIni.PutString("LOADER", "SystemRepositoryPath", this.mRepositoryPath);
                            loaderIni.Save();
                            loaderIni.Close();
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (InitializeMogRepository())
            {
                // Load up the target ini
                LoadSysIni();

                DisableEvents = false;

                if (!allUpToDate)
                {
                    mSplash.Visible = false;
                }

                if (!bRunning)
                {
                    RunBinary();
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }