Ejemplo n.º 1
0
        private void StationsSettingForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // 放送局を追加し忘れていると思われる場合
            if (stationNameTextBox.Text.Trim().Length != 0 && stationKindComboBox.Text.Trim().Length != 0)
            {
                // 追加するかを聞く
                DialogResult result = MessageBox.Show(
                    stationNameTextBox.Text.Trim() + "を追加しますか?\n(" + stationNameTextBox.Text.Trim() + "はまだ追加されていません)",
                    "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    CreateStation(stationKindComboBox.Text.Trim());
                }
            }

            // 設定の書き込み
            StationList.SetStationList((Station[])alStationList.ToArray(typeof(Station)));
            try
            {
                UserSetting.SaveSetting();
            }
            catch (IOException)
            {
                MessageBox.Show("設定ファイルが書き込めませんでした", "設定ファイル書き込みエラー");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 設定をファイルから読み込む
        /// </summary>
        public static void LoadSetting()
        {
            if (File.Exists(SettingPath))
            {
                FileStream    fs     = null;
                XmlTextReader reader = null;

                try
                {
                    fs     = new FileStream(SettingPath, FileMode.Open, FileAccess.Read);
                    reader = new XmlTextReader(fs);

                    ArrayList alStation = new ArrayList();

                    // StationListタグの中にいるか
                    bool inStationListFlag = false;

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.LocalName == "StationList")
                            {
                                inStationListFlag = true;
                            } // End of StationList
                            // StationListタグの中にいる場合
                            else if (inStationListFlag == true)
                            {
                                if (reader.LocalName == "Station")
                                {
                                    string       id          = string.Empty;
                                    string       name        = string.Empty;
                                    StationKinds stationKind = StationKinds.Netladio;

                                    if (reader.MoveToFirstAttribute())
                                    {
                                        id   = reader.GetAttribute("id");
                                        name = reader.GetAttribute("name");
                                        string kind = reader.GetAttribute("kind");
                                        if (kind == StationKinds.Netladio.ToString())
                                        {
                                            stationKind = StationKinds.Netladio;
                                        }
                                        else if (kind == StationKinds.RssPodcast.ToString())
                                        {
                                            stationKind = StationKinds.RssPodcast;
                                        }
                                        else if (kind == StationKinds.ShoutCast.ToString())
                                        {
                                            stationKind = StationKinds.ShoutCast;
                                        }
                                        else if (kind == StationKinds.Icecast.ToString())
                                        {
                                            stationKind = StationKinds.Icecast;
                                        }
                                        else
                                        {
                                            // ここに到達することはあり得ない
                                            Trace.Assert(false, "想定外の動作のため、終了します");
                                        }

                                        alStation.Add(new Station(id, name, stationKind));
                                    }
                                } // End of Station
                            }     // End of StationListタグの中にいる場合
                            else if (reader.LocalName == "FilterEnable")
                            {
                                string enable;
                                enable = reader.GetAttribute("enable");
                                if (enable == bool.TrueString)
                                {
                                    FilterEnable = true;
                                }
                                else if (enable == bool.FalseString)
                                {
                                    FilterEnable = false;
                                }
                            } // End of FilterEnable
                            else if (reader.LocalName.Equals("HeadlineTimer"))
                            {
                                if (reader.MoveToFirstAttribute())
                                {
                                    string check = reader.GetAttribute("check");
                                    if (check == bool.TrueString)
                                    {
                                        HeadlineTimerCheck = true;
                                    }
                                    else if (check == bool.FalseString)
                                    {
                                        HeadlineTimerCheck = false;
                                    }
                                    try
                                    {
                                        HeadlineTimerMillSecond = Convert.ToInt32(reader.GetAttribute("millsecond"));
                                    }
                                    catch (ArgumentException)
                                    {
                                        ;
                                    }
                                    catch (FormatException)
                                    {
                                        ;
                                    }
                                    catch (OverflowException)
                                    {
                                        ;
                                    }
                                }
                            } // End of HeadlineTimer
                            else if (reader.LocalName == "MediaPlayerPath")
                            {
                                MediaPlayerPath = reader.GetAttribute("path");
                            } // End of MediaPlayerPath
                            else if (reader.LocalName == "BrowserPath")
                            {
                                BrowserPath = reader.GetAttribute("path");
                            } // End of BrowserPath
                            else if (reader.LocalName == "PlayListSave")
                            {
                                string save;
                                save = reader.GetAttribute("save");
                                if (save == bool.TrueString)
                                {
                                    PlayListSave = true;
                                }
                                else if (save == bool.FalseString)
                                {
                                    PlayListSave = false;
                                }
                            } // End of PlayListSave
                            else if (reader.LocalName.Equals("HeadlineListBoxFont"))
                            {
                                if (reader.MoveToFirstAttribute())
                                {
                                    string check = reader.GetAttribute("change");
                                    if (check == bool.TrueString)
                                    {
                                        HeadlineListBoxFontSizeChange = true;
                                    }
                                    else if (check == bool.FalseString)
                                    {
                                        HeadlineListBoxFontSizeChange = false;
                                    }
                                    try
                                    {
                                        HeadlineListBoxFontSize = Convert.ToInt32(reader.GetAttribute("size"));
                                    }
                                    catch (ArgumentException)
                                    {
                                        ;
                                    }
                                    catch (FormatException)
                                    {
                                        ;
                                    }
                                    catch (OverflowException)
                                    {
                                        ;
                                    }
                                }
                            } // End of HeadlineListBoxFont
                            else if (reader.LocalName == "Proxy")
                            {
                                if (reader.MoveToFirstAttribute())
                                {
                                    string use = reader.GetAttribute("use");
                                    if (use == ProxyConnect.Unuse.ToString())
                                    {
                                        ProxyUse = ProxyConnect.Unuse;
                                    }
                                    else if (use == ProxyConnect.OsSetting.ToString())
                                    {
                                        ProxyUse = ProxyConnect.OsSetting;
                                    }
                                    else if (use == ProxyConnect.OriginalSetting.ToString())
                                    {
                                        ProxyUse = ProxyConnect.OriginalSetting;
                                    }

                                    ProxyServer = reader.GetAttribute("server");

                                    try
                                    {
                                        string port = reader.GetAttribute("port");
                                        ProxyPort = int.Parse(port);
                                    }
                                    catch (ArgumentException)
                                    {
                                        ;
                                    }
                                    catch (FormatException)
                                    {
                                        ;
                                    }
                                    catch (OverflowException)
                                    {
                                        ;
                                    }
                                }
                            } // End of Proxy
                        }
                        else if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            if (reader.LocalName == "StationList")
                            {
                                inStationListFlag = false;
                                StationList.SetStationList((Station[])alStation.ToArray(typeof(Station)));
                            }
                        }
                    }
                }
                finally
                {
                    reader.Close();
                    fs.Close();
                }
            }
        }