Beispiel #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("設定ファイルが書き込めませんでした", "設定ファイル書き込みエラー");
            }
        }
Beispiel #2
0
        private void StationsSettingForm_Load(object sender, EventArgs e)
        {
            SetAnchorControl();
            FixWindowSize();
            ButtonsEnable();

            // 放送局情報の読み込み
            foreach (Station station in StationList.GetStationList())
            {
                alStationList.Add(station);
                stationListBox.Items.Add(station.DisplayName);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 放送局を作成する。
        /// </summary>
        /// <param name="stationKind">放送局の種類</param>
        private void CreateStation(string stationKind)
        {
            Station station = null;

            switch (stationKind)
            {
            case "ねとらじ":
                station = StationList.CreateStation(stationNameTextBox.Text.Trim(), StationKinds.Netladio);
                break;

            case "Podcast":
                station = StationList.CreateStation(stationNameTextBox.Text.Trim(), StationKinds.RssPodcast);

                // 設定画面を呼び出す
                station.Headline.ShowSettingForm();
                break;

            case "SHOUTcast":
                station = StationList.CreateStation(stationNameTextBox.Text.Trim(), StationKinds.ShoutCast);

                // 設定画面を呼び出す
                station.Headline.ShowSettingForm();
                break;

            case "Icecast":
                station = StationList.CreateStation(stationNameTextBox.Text.Trim(), StationKinds.Icecast);

                // 設定画面を呼び出す
                station.Headline.ShowSettingForm();
                break;

            default:
                // ここに到達することはあり得ない
                Trace.Assert(false, "想定外の動作のため、終了します");
                break;
            }

            // リストに追加
            alStationList.Add(station);
            stationListBox.Items.Add(station.DisplayName);
            stationNameTextBox.Text = string.Empty;
        }
Beispiel #4
0
        /// <summary>
        /// 設定をファイルに保存
        /// </summary>
        public static void SaveSetting()
        {
            FileStream    fs     = null;
            XmlTextWriter writer = null;

            try
            {
                fs     = new FileStream(SettingPath, FileMode.Create, FileAccess.Write);
                writer = new XmlTextWriter(fs, Encoding.GetEncoding("utf-8"));

                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument(true);

                writer.WriteStartElement("Setting");

                writer.WriteStartElement("Header");

                writer.WriteStartElement("Name");
                writer.WriteAttributeString("name", PocketLadioInfo.ApplicationName);
                writer.WriteEndElement(); // End of Name.
                writer.WriteStartElement("Version");
                writer.WriteAttributeString("version", PocketLadioInfo.VersionNumber);
                writer.WriteEndElement(); // End of Version.

                writer.WriteStartElement("Date");
                writer.WriteAttributeString("date", DateTime.Now.ToString());
                writer.WriteEndElement(); // End of Date.

                writer.WriteEndElement(); // End of Header.

                writer.WriteStartElement("Content");

                writer.WriteStartElement("StationList");
                foreach (Station station in StationList.GetStationList())
                {
                    writer.WriteStartElement("Station");
                    writer.WriteAttributeString("id", station.Id);
                    writer.WriteAttributeString("name", station.Name);
                    writer.WriteAttributeString("kind", station.Kind.ToString());
                    writer.WriteEndElement(); // End of Station
                }
                writer.WriteEndElement();     // End of StationList

                writer.WriteStartElement("FilterEnable");
                writer.WriteAttributeString("enable", FilterEnable.ToString());
                writer.WriteEndElement(); // End of FilterEnable

                writer.WriteStartElement("HeadlineTimer");
                writer.WriteAttributeString("check", HeadlineTimerCheck.ToString());
                writer.WriteAttributeString("millsecond", HeadlineTimerMillSecond.ToString());
                writer.WriteEndElement(); // End of HeadlineTimer

                writer.WriteStartElement("MediaPlayerPath");
                writer.WriteAttributeString("path", MediaPlayerPath);
                writer.WriteEndElement(); // End of MediaPlayerPath

                writer.WriteStartElement("BrowserPath");
                writer.WriteAttributeString("path", BrowserPath);
                writer.WriteEndElement(); // End of BrowserPath

                writer.WriteStartElement("PlayListSave");
                writer.WriteAttributeString("save", PlayListSave.ToString());
                writer.WriteEndElement(); // End of PlayListSave

                writer.WriteStartElement("HeadlineListBoxFont");
                writer.WriteAttributeString("change", HeadlineListBoxFontSizeChange.ToString());
                writer.WriteAttributeString("size", HeadlineListBoxFontSize.ToString());
                writer.WriteEndElement(); // End of HeadlineListBoxFont

                writer.WriteStartElement("Proxy");
                writer.WriteAttributeString("use", ProxyUse.ToString());
                writer.WriteAttributeString("server", ProxyServer);
                writer.WriteAttributeString("port", ProxyPort.ToString());
                writer.WriteEndElement(); // End of Porxy

                writer.WriteEndElement(); // End of Content.

                writer.WriteEndElement(); // End of Setting.

                writer.WriteEndDocument();
            }
            finally
            {
                writer.Close();
                fs.Close();
            }
        }
Beispiel #5
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();
                }
            }
        }