Example #1
0
                /// <summary>
                /// XMLファイルから設定を読み込み、クラス内のプロパティに設定する
                /// </summary>
                ///
                /// <param name="filename">読み込むXMLファイル名</param>
                /// <returns>IDをキー、Passwodを値としたハッシュテーブル</returns>
                public static void loadSettings(string filename)
                {
                    string filepath = "";

                    if (Path.IsPathRooted(filename))
                    {
                        filepath = filename;
                        filename = Path.GetFileName(filename);
                    }
                    else
                    {
                        filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename);
                    }
                    if (File.Exists(filepath))
                    {
                        try
                        {
                            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(TricksterTools.Library.Xml.Settings.XmlTricksterRoot));
                            System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open);
                            TricksterTools.Library.Xml.Settings.XmlTricksterRoot XmlRoot = (TricksterTools.Library.Xml.Settings.XmlTricksterRoot)serializer.Deserialize(fs);
                            XmlSettings Tools = new XmlSettings();

                            if (XmlRoot.Tools.name != "TSLoginManager")
                            {
                                MessageBox.Show("TSLoginManager以外の設定ファイルが読み込まれています。" + Environment.NewLine + "設定は読み込まれませんでした。", "設定読み込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                HungUp.enable           = false;
                                HungUp.sec              = 60;
                                Update.startupAutoCehck = false;
                                Update.checkBetaVersion = false;
                                GameStartUp.mode        = RUN_GAME_DIRECT;
                                //Logging.enable = false;
                                //Logging.fileName = Environment.CurrentDirectory + @"\debug.log";
                                Icons.resourceName = "char99";

                                return;
                            }
                            Tools = XmlRoot.Tools.Settings;

                            // Logging設定

                            /*
                             * try
                             * {
                             *  if (Tools.Logging.enable == "true")
                             *  {
                             *      Logging.enable = true;
                             *  }
                             *  else
                             *  {
                             *      Logging.enable = false;
                             *  }
                             * }
                             * catch (Exception e)
                             * {
                             *  SimpleLogger.WriteLine(e.Message);
                             *  Logging.enable = false;
                             * }
                             * try
                             * {
                             *  Logging.filePath = Tools.Logging.Path;
                             * }
                             * catch (Exception e)
                             * {
                             *  SimpleLogger.WriteLine(e.Message);
                             *  Logging.filePath = Environment.CurrentDirectory + "\\logs";
                             * }
                             */

                            // アイコン設定
                            try
                            {
                                Icons.resourceName = Tools.Icon.resourceName;
                            }
                            catch (Exception e)
                            {
                                SimpleLogger.WriteLine(e.Message);
                                Icons.resourceName = "char99";  // default
                            }

                            // フリーズ設定
                            try
                            {
                                if (Tools.HungupTime.enable == "true")
                                {
                                    HungUp.enable = true;
                                }
                                else
                                {
                                    HungUp.enable = false;
                                }
                            }
                            catch (Exception e)
                            {
                                SimpleLogger.WriteLine(e.Message);
                                SimpleLogger.WriteLine("load default: [HungUp] enable");
                                HungUp.enable = true;
                            }
                            try
                            {
                                HungUp.sec = Tools.HungupTime.sec;
                            }
                            catch (Exception e)
                            {
                                SimpleLogger.WriteLine(e.Message);
                                SimpleLogger.WriteLine("load default: [HungUp] time = 60");
                                HungUp.sec = 60;
                            }

                            // アップデートチェック設定
                            try
                            {
                                if (Tools.UpdateCheck.startup.ToLower() == "true")
                                {
                                    Update.startupAutoCehck = true;
                                }
                                else
                                {
                                    Update.startupAutoCehck = false;
                                }
                            }
                            catch (Exception e)
                            {
                                SimpleLogger.WriteLine(e.Message);
                                SimpleLogger.WriteLine("load default: [StartupAutoCheck] false");
                                Update.startupAutoCehck = false;
                            }

                            // ベータアップデート設定
                            try
                            {
                                if (Tools.UpdateCheck.checkBeta.ToLower() == "true")
                                {
                                    Update.checkBetaVersion = true;
                                }
                                else
                                {
                                    Update.checkBetaVersion = false;
                                }
                            }
                            catch (Exception e)
                            {
                                SimpleLogger.WriteLine(e.Message);
                                SimpleLogger.WriteLine("load default: [BetaCheck] false");
                                Update.checkBetaVersion = false;
                            }

                            // ゲーム起動方法設定
                            try
                            {
                                GameStartUp.mode = Tools.StartUpGame.mode;
                            }
                            catch (Exception e)
                            {
                                SimpleLogger.WriteLine(e.Message);
                                SimpleLogger.WriteLine("load default: [GameStartUp] mode=0");
                                GameStartUp.mode = RUN_GAME_DIRECT;
                            }
                        }
                        catch (FileLoadException fle)
                        {
                            SimpleLogger.WriteLine(fle.Message);
                            MessageBox.Show("例外エラー:" + Environment.NewLine + "ファイルの読み込みに失敗しました。", "FileLoadException error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            HungUp.sec              = 60;
                            HungUp.enable           = true;
                            Update.startupAutoCehck = false;
                            Update.checkBetaVersion = false;
                            GameStartUp.mode        = RUN_GAME_DIRECT;
                            Icons.resourceName      = "char99";
                        }
                        catch (System.Xml.XmlException xe)
                        {
                            SimpleLogger.WriteLine(xe.Message);
                            MessageBox.Show("例外エラー:" + Environment.NewLine + "データの処理に失敗しました。", "XmlException error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            HungUp.sec              = 60;
                            HungUp.enable           = true;
                            Update.startupAutoCehck = false;
                            Update.checkBetaVersion = false;
                            GameStartUp.mode        = RUN_GAME_DIRECT;
                            Icons.resourceName      = "char99";
                        }
                        catch (System.InvalidOperationException ioe)
                        {
                            SimpleLogger.WriteLine(ioe.Message);
                            MessageBox.Show("例外エラー:" + Environment.NewLine + "無効なメソッドの呼び出しが行われました。", "InvalidOperationException error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            HungUp.sec              = 60;
                            HungUp.enable           = true;
                            Update.startupAutoCehck = false;
                            Update.checkBetaVersion = false;
                            GameStartUp.mode        = RUN_GAME_DIRECT;
                            Icons.resourceName      = "char99";
                        }
                    }
                    else
                    {
                        SimpleLogger.WriteLine("setting file 'settings.xml' could not read/found.");
                        MessageBox.Show("設定ファイルを読み込めませんでした。" + Environment.NewLine + "'" + filepath + "'", "TSLoginManager", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        HungUp.sec              = 60;
                        HungUp.enable           = true;
                        Update.startupAutoCehck = false;
                        Update.checkBetaVersion = false;
                        GameStartUp.mode        = RUN_GAME_DIRECT;
                        Icons.resourceName      = "char99";
                    }
                }
Example #2
0
                public static void saveSettings(string filename)
                {
                    TricksterTools.Library.Xml.Settings.XmlTricksterRoot XmlRoot = new TricksterTools.Library.Xml.Settings.XmlTricksterRoot();
                    XmlTools              Tools       = new XmlTools();
                    XmlSettings           Settings    = new XmlSettings();
                    XmlSettingHungUpTime  hungtime    = new XmlSettingHungUpTime();
                    XmlSettingUpdate      update      = new XmlSettingUpdate();
                    XmlSettingGameStartUp gamestartup = new XmlSettingGameStartUp();
                    XmlSettingLogging     logging     = new XmlSettingLogging();
                    XmlSettingIcons       icons       = new XmlSettingIcons();

                    hungtime.enable    = (HungUp.enable) ? "true" : "false";
                    hungtime.sec       = HungUp.sec;
                    update.startup     = (Update.startupAutoCehck) ? "true" : "false";
                    update.checkBeta   = (Update.checkBetaVersion) ? "true" : "false";
                    gamestartup.mode   = GameStartUp.mode;
                    logging.enable     = (Logging.enable) ? "true" : "false";
                    logging.Path       = Logging.filePath;
                    icons.resourceName = Icons.resourceName;

                    Settings.HungupTime  = hungtime;
                    Settings.UpdateCheck = update;
                    Settings.StartUpGame = gamestartup;
                    //Settings.Logging = logging;
                    Settings.Icon  = icons;
                    Tools.Settings = Settings;
                    XmlRoot.Tools  = Tools;


                    string filepath = "";

                    if (Path.IsPathRooted(filename))
                    {
                        filepath = filename;
                        filename = Path.GetFileName(filename);
                    }
                    else
                    {
                        filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename);
                    }

                    if (!File.Exists(filepath))
                    {
                        // ファイルがなければ作成
                        FileStream fs = new FileStream(filepath, FileMode.Create);
                        fs.Close();
                    }

                    try
                    {
                        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(TricksterTools.Library.Xml.Settings.XmlTricksterRoot));
                        FileStream fs = new FileStream(filepath, FileMode.Create);
                        serializer.Serialize(fs, XmlRoot);
                        fs.Close();
                    }
                    catch (System.Security.SecurityException se)
                    {
                        SimpleLogger.WriteLine(se.Message);
                        //MessageBox.Show("例外エラー:" + Environment.NewLine + "セキュリティエラーです。", "SecurityExceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw se;
                    }
                    catch (System.IO.IOException ioe)
                    {
                        SimpleLogger.WriteLine(ioe.Message);
                        //MessageBox.Show("例外エラー:" + Environment.NewLine + "入出力時にエラーが発生しました。", "IOExceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw ioe;
                    }
                    catch (System.Xml.XmlException xe)
                    {
                        SimpleLogger.WriteLine(xe.Message);
                        //MessageBox.Show("例外エラー:" + Environment.NewLine + "設定読み込みエラー", "XmlExceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw xe;
                    }
                    catch (System.Exception e)
                    {
                        SimpleLogger.WriteLine(e.Message);
                        //MessageBox.Show("例外エラー:" + Environment.NewLine + "原因の特定ができませんでした。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw e;
                    }
                }