예제 #1
0
        /// <summary>
        /// Load the race images.
        /// </summary>
        /// <returns>Returns true if the race icons were successfuly loaded.</returns>
        public static bool Restore()
        {
            if (Data.IconList.Count < 1)
            {
                try
                {
                    using (Config conf = new Config())
                    {
                        var graphicFolder = FileSearcher.GetGraphicsPath();



                        // load the icons
                        DirectoryInfo info = new DirectoryInfo(Path.Combine(graphicFolder, "Race"));
                        foreach (FileInfo fi in info.GetFiles())
                        {
                            Bitmap   i    = new Bitmap(Path.Combine(fi.DirectoryName, fi.Name));
                            RaceIcon icon = new RaceIcon(fi.Name, i);
                            Data.IconList.Add(icon);
                        }
                    }
                }
                catch
                {
                    Report.Error("RaceIcon: Restore() - Failed to load race icons.");
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
파일: Config.cs 프로젝트: ekolis/stars-nova
        /// <summary>
        /// Restore the configuration settings from nova.conf.
        /// </summary>
        /// <remarks>
        /// If there is no configuration file yet it will be created when the
        /// settings are saved for the first time.
        /// </remarks>
        public void Restore()
        {
            string fileName = FileSearcher.GetConfigFile();

            if (File.Exists(fileName))
            {
                bool   waitForFile = false;
                double waitTime    = 0; // seconds
                do
                {
                    try
                    {
                        using (FileStream confFile = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                        {
                            // Data = Serializer.Deserialize(state) as GameSettings;
                            XmlSerializer s    = new XmlSerializer(typeof(Config));
                            Config        data = new Config();
                            data = (Config)s.Deserialize(confFile);

                            foreach (KeyValuePair <string, string> setting in data.settings)
                            {
                                if (this.settings.ContainsKey(setting.Key))
                                {
                                    this.settings[setting.Key] = setting.Value.ToString();
                                }
                                else
                                {
                                    this.settings.Add(setting.Key, setting.Value);
                                }
                            }
                            waitForFile = false;
                        }
                    }
                    catch (System.IO.IOException)
                    {
                        // IOException. Is the file locked? Try waiting.
                        if (waitTime < Global.TotalFileWaitTime)
                        {
                            waitForFile = true;
                            System.Threading.Thread.Sleep(Global.FileWaitRetryTime);
                            waitTime += 0.1;
                        }
                        else
                        {
                            // Give up, maybe something else is wrong?
                            throw;
                        }
                    }
                }while (waitForFile);
            }

            this.initialized = true;
        }
예제 #3
0
파일: Config.cs 프로젝트: ekolis/stars-nova
        /// <summary>
        /// Save the console persistent data.
        /// </summary>
        public void Save()
        {
            string fileName = FileSearcher.GetConfigFile();

            if (fileName == null)
            {
                // TODO (priority 5) add the nicities. Update the config files location.
                SaveFileDialog fd = new SaveFileDialog();
                fd.Title = "Choose a location to save the nova.config file.";

                DialogResult result = fd.ShowDialog();
                if (result == DialogResult.OK)
                {
                    fileName = fd.FileName;
                }
                else
                {
                    throw new System.IO.IOException("File dialog cancelled.");
                }
            }

            bool   waitForFile = false;
            double waitTime    = 0.0; // seconds

            do
            {
                try
                {
                    using (Stream stream = new FileStream(fileName, FileMode.Create))
                    {
                        XmlSerializer s = new XmlSerializer(typeof(Config));
                        s.Serialize(stream, this);
                    }
                    waitForFile = false;
                }
                catch (System.IO.IOException)
                {
                    // IOException. Is the file locked? Try waiting.
                    if (waitTime < Global.TotalFileWaitTime)
                    {
                        waitForFile = true;
                        System.Threading.Thread.Sleep(Global.FileWaitRetryTime);
                        waitTime += 0.1;
                    }
                    else
                    {
                        // Give up, maybe something else is wrong?
                        throw;
                    }
                }
            }while (waitForFile);
        }
예제 #4
0
        //-------------------------------------------------------------------
        /// <summary>
        /// Restore the persistent data.
        /// </summary>
        //-------------------------------------------------------------------
        public static void Restore()
        {
            string fileName = Data.SettingsPathName;

            if (fileName == null)
            {
                fileName = FileSearcher.GetSettingsFile();
            }
            if (File.Exists(fileName))
            {
                using (FileStream state = new FileStream(fileName, FileMode.Open))
                {
                    // Data = Serializer.Deserialize(state) as GameSettings;
                    XmlSerializer s = new XmlSerializer(typeof(GameSettings));
                    Data = (GameSettings)s.Deserialize(state);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Restore the persistent data.
        /// </summary>
        public static void Restore()
        {
            string fileName = Data.SettingsPathName;

            if (fileName == null)
            {
                fileName = FileSearcher.GetSettingsFile();
            }
            if (File.Exists(fileName))
            {
                bool   waitForFile = false;
                double waitTime    = 0.0; // seconds
                do
                {
                    try
                    {
                        using (FileStream state = new FileStream(fileName, FileMode.Open))
                        {
                            // Data = Serializer.Deserialize(state) as GameSettings;
                            XmlSerializer s = new XmlSerializer(typeof(GameSettings));
                            Data = (GameSettings)s.Deserialize(state);
                        }
                        waitForFile = false;
                    }
                    catch (System.IO.IOException)
                    {
                        // IOException. Is the file locked? Try waiting.
                        if (waitTime < Global.TotalFileWaitTime)
                        {
                            waitForFile = true;
                            System.Threading.Thread.Sleep(Global.FileWaitRetryTime);
                            waitTime += 0.1;
                        }
                        else
                        {
                            // Give up, maybe something else is wrong?
                            throw;
                        }
                    }
                }while (waitForFile);
            }
        }