예제 #1
0
        private static void InitializeProgram()
        {
            Program.splashForm.StepProgress("ルートオプションの読み込み");
            if (!RootOptions.TryDeserialize(Path.Combine(Program.GetWorkingDirectory(WorkingDirectory.UserSettings), "RootOptions.xml"), out Program.rootOptions)) {
                Program.rootOptions = new RootOptions();
            }

            Program.splashForm.StepProgress("アイコンの読み込み");
            try {
                string iconFileName = Program.RootOptions.AppBasicOptions.IconFile;
                if (string.IsNullOrEmpty(iconFileName)) {
                    iconFileName = Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".ico";
                }
                if (File.Exists(iconFileName)) {
                    BaseForm.CustomIcon = new Icon(iconFileName);
                }
            } catch (Exception e) {
                Program.DisplayException("アイコンの読み込みエラー", e);
            }

            Program.splashForm.StepProgress("クッキーの設定");
            Program.cookieContainer = new CookieContainer();
            try {
            retry:
                int cookieSize = 0;
                if (!WindowsFunctions.InternetGetCookie(GUriBuilder.TopPageUri.AbsoluteUri, null, null, ref cookieSize)) {
                    if (Marshal.GetLastWin32Error() != (int)WinError.ERROR_NO_MORE_ITEMS) {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    } else {
                        switch (MessageBox.Show("クッキーの読み込みに失敗しました.視聴設定ページで視聴設定を行ってください.\n\n・はい: 視聴設定用のウィンドウを開く\n・いいえ: この警告を無視してアプリケーションを起動する\n・キャンセル: アプリケーションを終了する", "クッキーの読み込み失敗", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)) {
                            case DialogResult.Yes:
                                RegistrationForm regForm = new RegistrationForm();
                                regForm.ShowDialog();
                                regForm.Dispose();
                                goto retry;
                            case DialogResult.No:
                                break;
                            case DialogResult.Cancel:
                                Environment.Exit(0);
                                return;
                        }
                    }
                } else {
                    StringBuilder cookieSb = new StringBuilder(cookieSize);
                    if (!WindowsFunctions.InternetGetCookie(GUriBuilder.TopPageUri.AbsoluteUri, null, cookieSb, ref cookieSize)) {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }
                    string cookieStr = cookieSb.ToString();
                    if (!cookieStr.Contains("Cookie_UserId")) {
                        switch (MessageBox.Show("クッキーに Cookie_UserId がありません.視聴設定ページで視聴設定を行ってください.\n\n・はい: 視聴設定用のウィンドウを開く\n・いいえ: この警告を無視してアプリケーションを起動する\n・キャンセル: アプリケーションを終了する\n\nクッキーの中身:\n" + cookieStr, "Cookie_UserId がない", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)) {
                            case DialogResult.Yes:
                                RegistrationForm regForm = new RegistrationForm();
                                regForm.ShowDialog();
                                regForm.Dispose();
                                goto retry;
                            case DialogResult.No:
                                break;
                            case DialogResult.Cancel:
                                Environment.Exit(0);
                                return;
                        }
                    }
                    Program.cookieContainer.SetCookies(GUriBuilder.TopPageUri, cookieSb.ToString().Replace(';', ','));
                }
            } catch (Exception e) {
                Program.DisplayException("クッキーの読み込み失敗", e);
            }

            Program.splashForm.StepProgress("キャッシュの初期化と読み込み");
            Program.cacheController = new CacheController(Program.GetWorkingDirectory(WorkingDirectory.Cache), Program.CookieContainer, Program.RootOptions.CacheControllerOptions);
            if (Program.RootOptions.AppBasicOptions.UseDefaultGenres) {
                Program.CacheController.ResetToDefaultGenres();
            } else {
                Program.CacheController.DeserializeGenreTable();
            }
            Program.cacheController.DeserializePackageAndContentTables();

            Program.splashForm.StepProgress("プレイリストコレクションの読み込み");
            Program.playlistsManager = new PlaylistsManager();
            Program.playlistsManager.DeserializePlaylists(Path.Combine(Program.GetWorkingDirectory(WorkingDirectory.UserSettings), "PlaylistCollection.xml"));

            Program.splashForm.StepProgress("仕分けルールの読み込み");
            Program.contentClassificatinoRulesManager = new ContentClassificationRulesManager();
            Program.contentClassificatinoRulesManager.TryDeserialize(Path.Combine(Program.GetWorkingDirectory(WorkingDirectory.UserSettings), "ContentClassificationRules.xml"));

            Program.splashForm.StepProgress("外部コマンドの読み込み");
            Program.externalCommandsManager = new ExternalCommandsManager();
            Program.externalCommandsManager.TryDeserialize(Path.Combine(Program.GetWorkingDirectory(WorkingDirectory.UserSettings), "ExternalCommands.xml"));

            Program.splashForm.StepProgress("メインフォームの作成");
            Program.mainForm = new MainForm();
        }
예제 #2
0
 internal void NeutralizeUnspecificValues(MainForm mainForm)
 {
     if (this.CrawlResultViewWidth < 0) this.CrawlResultViewWidth = mainForm.CrawlResultViewWidth;
     if (this.CrawlResultViewHeight < 0) this.CrawlResultViewHeight = mainForm.CrawlResultViewHeight;
 }