コード例 #1
0
ファイル: formMain.Start.cs プロジェクト: NeXuSTrain/OpenBVE
        // show train
        private void ShowTrain(bool UserSelectedEncoding)
        {
            if (!UserSelectedEncoding)
            {
                comboboxTrainEncoding.Tag           = new object();
                comboboxTrainEncoding.SelectedIndex = 0;
                comboboxTrainEncoding.Items[0]      = "(UTF-8)";
                comboboxTrainEncoding.Tag           = null;
                Result.TrainEncoding = System.Text.Encoding.UTF8;
                switch (Interface.GetEncodingFromFile(Result.TrainFolder, "train.txt"))
                {
                case Interface.Encoding.Utf8:
                    comboboxTrainEncoding.SelectedIndex = 0;
                    comboboxTrainEncoding.Items[0]      = "(UTF-8)";
                    Result.TrainEncoding = System.Text.Encoding.UTF8;
                    break;

                case Interface.Encoding.Utf16Le:
                    comboboxTrainEncoding.SelectedIndex = 0;
                    comboboxTrainEncoding.Items[0]      = "(UTF-16 little endian)";
                    Result.TrainEncoding = System.Text.Encoding.Unicode;
                    break;

                case Interface.Encoding.Utf16Be:
                    comboboxTrainEncoding.SelectedIndex = 0;
                    comboboxTrainEncoding.Items[0]      = "(UTF-16 big endian)";
                    Result.TrainEncoding = System.Text.Encoding.BigEndianUnicode;
                    break;

                case Interface.Encoding.Utf32Le:
                    comboboxTrainEncoding.SelectedIndex = 0;
                    comboboxTrainEncoding.Items[0]      = "(UTF-32 little endian)";
                    Result.TrainEncoding = System.Text.Encoding.UTF32;
                    break;

                case Interface.Encoding.Utf32Be:
                    comboboxTrainEncoding.SelectedIndex = 0;
                    comboboxTrainEncoding.Items[0]      = "(UTF-32 big endian)";
                    Result.TrainEncoding = System.Text.Encoding.GetEncoding(12001);
                    break;
                }
                int i;
                for (i = 0; i < Interface.CurrentOptions.TrainEncodings.Length; i++)
                {
                    if (Interface.CurrentOptions.TrainEncodings[i].Value == Result.TrainFolder)
                    {
                        int j;
                        for (j = 1; j < EncodingCodepages.Length; j++)
                        {
                            if (EncodingCodepages[j] == Interface.CurrentOptions.TrainEncodings[i].Codepage)
                            {
                                comboboxTrainEncoding.SelectedIndex = j;
                                Result.TrainEncoding = System.Text.Encoding.GetEncoding(EncodingCodepages[j]);
                                break;
                            }
                        }
                        if (j == EncodingCodepages.Length)
                        {
                            comboboxTrainEncoding.SelectedIndex = 0;
                            Result.TrainEncoding = System.Text.Encoding.UTF8;
                        }
                        break;
                    }
                }
                panelTrainEncoding.Enabled = true;
                comboboxTrainEncoding.Tag  = null;
            }
            {
                // train image
                string File = OpenBveApi.Path.CombineFile(Result.TrainFolder, "train.png");
                if (!System.IO.File.Exists(File))
                {
                    File = OpenBveApi.Path.CombineFile(Result.TrainFolder, "train.bmp");
                }
                if (System.IO.File.Exists(File))
                {
                    try {
                        pictureboxTrainImage.Image = Image.FromFile(File);
                    } catch {
                        pictureboxTrainImage.Image = null;
                        TryLoadImage(pictureboxTrainImage, "train_error.png");
                    }
                }
                else
                {
                    TryLoadImage(pictureboxTrainImage, "train_unknown.png");
                }
            }
            {
                // train description
                string File = OpenBveApi.Path.CombineFile(Result.TrainFolder, "train.txt");
                if (System.IO.File.Exists(File))
                {
                    try {
                        string trainText = System.IO.File.ReadAllText(File, Result.TrainEncoding);
                        trainText = Interface.ConvertNewlinesToCrLf(trainText);
                        textboxTrainDescription.Text     = trainText;
                        textboxTrainEncodingPreview.Text = trainText;
                    } catch {
                        textboxTrainDescription.Text     = System.IO.Path.GetFileName(Result.TrainFolder);
                        textboxTrainEncodingPreview.Text = "";
                    }
                }
                else
                {
                    textboxTrainDescription.Text     = System.IO.Path.GetFileName(Result.TrainFolder);
                    textboxTrainEncodingPreview.Text = "";
                }
            }
            groupboxTrainDetails.Visible        = true;
            labelTrainEncoding.Enabled          = true;
            labelTrainEncodingPreview.Enabled   = true;
            textboxTrainEncodingPreview.Enabled = true;
            buttonStart.Enabled = Result.RouteFile != null & Result.TrainFolder != null;
        }
コード例 #2
0
ファイル: formMain.Start.cs プロジェクト: NeXuSTrain/OpenBVE
        // show route
        private void ShowRoute(bool UserSelectedEncoding)
        {
            if (Result.RouteFile != null && !routeWorkerThread.IsBusy)
            {
                this.Cursor = Cursors.WaitCursor;
                TryLoadImage(pictureboxRouteImage, "loading.png");
                groupboxRouteDetails.Visible = true;
                textboxRouteDescription.Text = Interface.GetInterfaceString("start_route_processing");

                // determine encoding
                if (!UserSelectedEncoding)
                {
                    comboboxRouteEncoding.Tag           = new object();
                    comboboxRouteEncoding.SelectedIndex = 0;
                    comboboxRouteEncoding.Items[0]      = "(UTF-8)";
                    comboboxRouteEncoding.Tag           = null;
                    Result.RouteEncoding = System.Text.Encoding.UTF8;
                    switch (Interface.GetEncodingFromFile(Result.RouteFile))
                    {
                    case Interface.Encoding.Utf7:
                        panelRouteEncoding.Enabled          = false;
                        comboboxRouteEncoding.SelectedIndex = 0;
                        comboboxRouteEncoding.Items[0]      = "(UTF-7)";
                        Result.RouteEncoding = System.Text.Encoding.UTF7;
                        break;

                    case Interface.Encoding.Utf8:
                        panelRouteEncoding.Enabled          = false;
                        comboboxRouteEncoding.SelectedIndex = 0;
                        comboboxRouteEncoding.Items[0]      = "(UTF-8)";
                        Result.RouteEncoding = System.Text.Encoding.UTF8;
                        break;

                    case Interface.Encoding.Utf16Le:
                        panelRouteEncoding.Enabled          = false;
                        comboboxRouteEncoding.SelectedIndex = 0;
                        comboboxRouteEncoding.Items[0]      = "(UTF-16 little endian)";
                        Result.RouteEncoding = System.Text.Encoding.Unicode;
                        break;

                    case Interface.Encoding.Utf16Be:
                        panelRouteEncoding.Enabled          = false;
                        comboboxRouteEncoding.SelectedIndex = 0;
                        comboboxRouteEncoding.Items[0]      = "(UTF-16 big endian)";
                        Result.RouteEncoding = System.Text.Encoding.BigEndianUnicode;
                        break;

                    case Interface.Encoding.Utf32Le:
                        panelRouteEncoding.Enabled          = false;
                        comboboxRouteEncoding.SelectedIndex = 0;
                        comboboxRouteEncoding.Items[0]      = "(UTF-32 little endian)";
                        Result.RouteEncoding = System.Text.Encoding.UTF32;
                        break;

                    case Interface.Encoding.Utf32Be:
                        panelRouteEncoding.Enabled          = false;
                        comboboxRouteEncoding.SelectedIndex = 0;
                        comboboxRouteEncoding.Items[0]      = "(UTF-32 big endian)";
                        Result.RouteEncoding = System.Text.Encoding.GetEncoding(12001);
                        break;
                    }
                    panelRouteEncoding.Enabled = true;
                    comboboxRouteEncoding.Tag  = new object();

                    int i;
                    for (i = 0; i < Interface.CurrentOptions.RouteEncodings.Length; i++)
                    {
                        if (Interface.CurrentOptions.RouteEncodings[i].Value == Result.RouteFile)
                        {
                            int j;
                            for (j = 1; j < EncodingCodepages.Length; j++)
                            {
                                if (EncodingCodepages[j] == Interface.CurrentOptions.RouteEncodings[i].Codepage)
                                {
                                    comboboxRouteEncoding.SelectedIndex = j;
                                    Result.RouteEncoding = System.Text.Encoding.GetEncoding(EncodingCodepages[j]);
                                    break;
                                }
                            }
                            if (j == EncodingCodepages.Length)
                            {
                                comboboxRouteEncoding.SelectedIndex = 0;
                                Result.RouteEncoding = System.Text.Encoding.UTF8;
                            }
                            break;
                        }
                    }
                    comboboxRouteEncoding.Tag = null;
                }
                routeWorkerThread.RunWorkerAsync();
            }
        }