Esempio n. 1
0
        public static string GetLanguageCode()
        {
            switch (ResourceHelper.GetCurrentLanguage())
            {
            case Language.English: return("en");

            case Language.French: return("fr");

            case Language.Japanese: return("ja");

            case Language.Russian: return("ru");

            case Language.Spanish: return("es");

            case Language.Ukrainian: return("uk");

            case Language.Portuguese: return("pt");

            case Language.Catalan: return("ca");
            }

            return("");
        }
Esempio n. 2
0
        private void mnuPreferences_Click(object sender, EventArgs e)
        {
            using (frmPreferences frm = new frmPreferences()) {
                VsDualOutputOption originalVsDualOutput = ConfigManager.Config.PreferenceInfo.VsDualVideoOutput;

                if (frm.ShowDialog(sender, this) == DialogResult.OK)
                {
                    VsDualOutputOption newVsDualOutput = ConfigManager.Config.PreferenceInfo.VsDualVideoOutput;
                    if (originalVsDualOutput != newVsDualOutput)
                    {
                        if (newVsDualOutput == VsDualOutputOption.Both || originalVsDualOutput == VsDualOutputOption.Both)
                        {
                            UpdateViewerSize(true);
                        }
                        else
                        {
                            UpdateDualSystemViewer();
                        }
                    }
                    ResourceHelper.LoadResources(ConfigManager.Config.PreferenceInfo.DisplayLanguage);
                    ResourceHelper.UpdateEmuLanguage();
                    ResourceHelper.ApplyResources(this);
                    UpdateMenus();
                    InitializeNsfMode();
                    ctrlRecentGames.UpdateGameInfo();
                    TopMost         = ConfigManager.Config.PreferenceInfo.AlwaysOnTop;
                    FormBorderStyle = ConfigManager.Config.PreferenceInfo.DisableMouseResize ? FormBorderStyle.Fixed3D : FormBorderStyle.Sizable;
                }
                else
                {
                    UpdateVideoSettings();
                    UpdateMenus();
                    UpdateViewerSize();
                }
            }
            ResizeRecentGames(sender, e);
        }
Esempio n. 3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            lblExample.Font          = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 2);
            txtAudioOptions.Font     = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 4);
            txtEmulationOptions.Font = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 4);
            txtVideoOptions.Font     = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 4);
            txtGeneralOptions.Font   = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 4);

            lblExample.Text = ConvertSlashes(lblExample.Text);

            StringBuilder sb = new StringBuilder();

            DisplayOptions(typeof(VideoInfo), sb);
            txtVideoOptions.Text = ConvertSlashes(sb.ToString().Trim());

            sb.Clear();
            DisplayOptions(typeof(AudioInfo), sb);
            txtAudioOptions.Text = ConvertSlashes(sb.ToString().Trim());

            sb.Clear();
            DisplayOptions(typeof(EmulationInfo), sb);
            txtEmulationOptions.Text = ConvertSlashes(sb.ToString().Trim());

            sb.Clear();
            DisplayOptions(typeof(Configuration), sb);

            txtGeneralOptions.Text = ConvertSlashes(
                ResourceHelper.GetMessage("HelpFullscreen") + Environment.NewLine +
                ResourceHelper.GetMessage("HelpDoNotSaveSettings") + Environment.NewLine +
                ResourceHelper.GetMessage("HelpRecordMovie") + Environment.NewLine +
                ResourceHelper.GetMessage("HelpLoadLastSession") + Environment.NewLine +
                sb.ToString().Trim()
                );
        }
Esempio n. 4
0
        public void UpdateUI()
        {
            this.Updating = true;

            foreach (KeyValuePair <string, Control> kvp in _bindings)
            {
                if (!_fieldInfo.ContainsKey(kvp.Key))
                {
                    throw new Exception("Invalid binding key");
                }
                else
                {
                    FieldInfoWrapper field  = _fieldInfo[kvp.Key];
                    eNumberFormat    format = _fieldFormat[kvp.Key];
                    object           value  = field.GetValue(this.Entity);
                    if (kvp.Value is TextBox)
                    {
                        if (value is IFormattable)
                        {
                            kvp.Value.Text = ((IFormattable)value).ToString(format == eNumberFormat.Decimal ? "" : "X", System.Globalization.CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            kvp.Value.Text = value == null ? "" : ((string)value).Replace(Environment.NewLine, "\n").Replace("\n", Environment.NewLine);
                        }
                    }
                    else if (kvp.Value is ctrlPathSelection)
                    {
                        kvp.Value.Text = (string)value;
                    }
                    else if (kvp.Value is CheckBox)
                    {
                        ((CheckBox)kvp.Value).Checked = Convert.ToBoolean(value);
                    }
                    else if (kvp.Value is ctrlRiskyOption)
                    {
                        ((ctrlRiskyOption)kvp.Value).Checked = Convert.ToBoolean(value);
                    }
                    else if (kvp.Value is RadioButton)
                    {
                        ((RadioButton)kvp.Value).Checked = (bool)value;
                    }
                    else if (kvp.Value is Panel)
                    {
                        RadioButton radio = kvp.Value.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Tag.Equals(value));
                        if (radio != null)
                        {
                            radio.Checked = true;
                        }
                        else
                        {
                            throw new Exception("No radio button matching value found");
                        }
                    }
                    else if (kvp.Value is ctrlTrackbar)
                    {
                        if (field.FieldType == typeof(Int32))
                        {
                            ((ctrlTrackbar)kvp.Value).Value = (int)value;
                        }
                        else
                        {
                            ((ctrlTrackbar)kvp.Value).Value = (int)(uint)value;
                        }
                    }
                    else if (kvp.Value is ctrlHorizontalTrackbar)
                    {
                        ((ctrlHorizontalTrackbar)kvp.Value).Value = (int)value;
                    }
                    else if (kvp.Value is TrackBar)
                    {
                        if (field.FieldType == typeof(Int32))
                        {
                            ((TrackBar)kvp.Value).Value = (int)value;
                        }
                        else
                        {
                            ((TrackBar)kvp.Value).Value = (int)(uint)value;
                        }
                    }
                    else if (kvp.Value is MesenNumericUpDown)
                    {
                        MesenNumericUpDown nud = kvp.Value as MesenNumericUpDown;
                        decimal            val;
                        if (field.FieldType == typeof(UInt32))
                        {
                            val = (UInt32)value;
                        }
                        else if (field.FieldType == typeof(Int32))
                        {
                            val = (Int32)value;
                        }
                        else
                        {
                            val = (decimal)(double)value;
                        }
                        val       = Math.Min(Math.Max(val, nud.Minimum), nud.Maximum);
                        nud.Value = val;
                    }
                    else if (kvp.Value is ComboBox)
                    {
                        ComboBox combo = kvp.Value as ComboBox;
                        if (value is Enum)
                        {
                            combo.SelectedItem = ResourceHelper.GetEnumText((Enum)value);
                        }
                        else if (field.FieldType == typeof(UInt32))
                        {
                            for (int i = 0, len = combo.Items.Count; i < len; i++)
                            {
                                UInt32 numericValue;
                                string item = Regex.Replace(combo.Items[i].ToString(), "[^0-9]", "");
                                if (UInt32.TryParse(item, out numericValue))
                                {
                                    if (numericValue == (UInt32)value)
                                    {
                                        combo.SelectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                        else if (field.FieldType == typeof(string))
                        {
                            combo.SelectedItem = value;
                            if (combo.SelectedIndex < 0 && combo.Items.Count > 0)
                            {
                                combo.SelectedIndex = 0;
                            }
                        }
                    }
                }
            }

            this.Updating = false;
        }
Esempio n. 5
0
        private void mnuInstallHdPack_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog()) {
                ofd.SetFilter(ResourceHelper.GetMessage("FilterZipFiles"));
                if (ofd.ShowDialog(this) == DialogResult.OK)
                {
                    try {
                        using (FileStream stream = File.Open(ofd.FileName, FileMode.Open)) {
                            ZipArchive zip = new ZipArchive(stream);

                            //Find the hires.txt file
                            ZipArchiveEntry hiresEntry = null;
                            foreach (ZipArchiveEntry entry in zip.Entries)
                            {
                                if (entry.Name == "hires.txt")
                                {
                                    hiresEntry = entry;
                                    break;
                                }
                            }

                            if (hiresEntry != null)
                            {
                                using (Stream entryStream = hiresEntry.Open()) {
                                    using (StreamReader reader = new StreamReader(entryStream)) {
                                        string  hiresData = reader.ReadToEnd();
                                        RomInfo romInfo   = InteropEmu.GetRomInfo();

                                        //If there's a "supportedRom" tag, check if it matches the current ROM
                                        Regex supportedRomRegex = new Regex("<supportedRom>([^\\n]*)");
                                        Match match             = supportedRomRegex.Match(hiresData);
                                        if (match.Success)
                                        {
                                            if (!match.Groups[1].Value.ToUpper().Contains(InteropEmu.GetRomInfo().Sha1.ToUpper()))
                                            {
                                                MesenMsgBox.Show("InstallHdPackWrongRom", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                return;
                                            }
                                        }

                                        //Extract HD pack
                                        try {
                                            string targetFolder = Path.Combine(ConfigManager.HdPackFolder, romInfo.GetRomName());
                                            if (Directory.Exists(targetFolder))
                                            {
                                                //Warn if the folder already exists
                                                if (MesenMsgBox.Show("InstallHdPackConfirmOverwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, targetFolder) != DialogResult.OK)
                                                {
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                Directory.CreateDirectory(targetFolder);
                                            }

                                            string hiresFileFolder = hiresEntry.FullName.Substring(0, hiresEntry.FullName.Length - "hires.txt".Length);
                                            foreach (ZipArchiveEntry entry in zip.Entries)
                                            {
                                                //Extract only the files in the same subfolder as the hires.txt file (and only if they have a name & size > 0)
                                                if (!string.IsNullOrWhiteSpace(entry.Name) && entry.Length > 0 && entry.FullName.StartsWith(hiresFileFolder))
                                                {
                                                    entry.ExtractToFile(Path.Combine(targetFolder, entry.Name), true);
                                                }
                                            }
                                        } catch (Exception ex) {
                                            MesenMsgBox.Show("InstallHdPackError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString());
                                            return;
                                        }
                                    }

                                    //Turn on HD Pack support automatically after installation succeeds
                                    ConfigManager.Config.VideoInfo.UseHdPacks = true;
                                    ConfigManager.ApplyChanges();
                                    ConfigManager.Config.ApplyConfig();

                                    if (MesenMsgBox.Show("InstallHdPackConfirmReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                                    {
                                        //Power cycle game if the user agrees
                                        InteropEmu.PowerCycle();
                                    }
                                }
                            }
                            else
                            {
                                MesenMsgBox.Show("InstallHdPackInvalidPack", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    } catch {
                        //Invalid file (file missing, not a zip file, etc.)
                        MesenMsgBox.Show("InstallHdPackInvalidZipFile", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Esempio n. 6
0
        private void mnuOnlineHelp_Click(object sender, EventArgs e)
        {
            string platform = Program.IsMono ? "linux" : "win";

            Process.Start("http://www.mesen.ca/docs/?v=" + InteropEmu.GetMesenVersion() + "&p=" + platform + "&l=" + ResourceHelper.GetLanguageCode());
        }
Esempio n. 7
0
        private void CheckForUpdates(bool displayResult)
        {
            Task.Run(() => {
                try {
                    using (var client = new WebClient()) {
                        XmlDocument xmlDoc = new XmlDocument();

                        string platform = Program.IsMono ? "linux" : "win";
                        xmlDoc.LoadXml(client.DownloadString("http://www.mesen.ca/Services/GetLatestVersion.php?v=" + InteropEmu.GetMesenVersion() + "&p=" + platform + "&l=" + ResourceHelper.GetLanguageCode()));
                        Version currentVersion = new Version(InteropEmu.GetMesenVersion());
                        Version latestVersion  = new Version(xmlDoc.SelectSingleNode("VersionInfo/LatestVersion").InnerText);
                        string changeLog       = xmlDoc.SelectSingleNode("VersionInfo/ChangeLog").InnerText;
                        string fileHash        = xmlDoc.SelectSingleNode("VersionInfo/Sha1Hash").InnerText;
                        string donateText      = xmlDoc.SelectSingleNode("VersionInfo/DonateText")?.InnerText;

                        if (latestVersion > currentVersion)
                        {
                            this.BeginInvoke((MethodInvoker)(() => {
                                using (frmUpdatePrompt frmUpdate = new frmUpdatePrompt(currentVersion, latestVersion, changeLog, fileHash, donateText)) {
                                    if (frmUpdate.ShowDialog(null, this) == DialogResult.OK)
                                    {
                                        Close();
                                    }
                                }
                            }));
                        }
                        else if (displayResult)
                        {
                            MesenMsgBox.Show("MesenUpToDate", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                } catch (Exception ex) {
                    if (displayResult)
                    {
                        MesenMsgBox.Show("ErrorWhileCheckingUpdates", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString());
                    }
                }
            });
        }
Esempio n. 8
0
        protected void UpdateUI()
        {
            this.Updating = true;

            foreach (KeyValuePair <string, Control> kvp in _bindings)
            {
                if (!_fieldInfo.ContainsKey(kvp.Key))
                {
                    throw new Exception("Invalid binding key");
                }
                else
                {
                    FieldInfo field = _fieldInfo[kvp.Key];
                    object    value = field.GetValue(this.Entity);
                    if (kvp.Value is TextBox)
                    {
                        if (field.FieldType == typeof(UInt32))
                        {
                            kvp.Value.Text = ((UInt32)value).ToString("X");
                        }
                        else if (field.FieldType == typeof(Byte))
                        {
                            kvp.Value.Text = ((Byte)value).ToString("X");
                        }
                        else
                        {
                            kvp.Value.Text = (string)value;
                        }
                    }
                    else if (kvp.Value is CheckBox)
                    {
                        ((CheckBox)kvp.Value).Checked = (bool)value;
                    }
                    else if (kvp.Value is RadioButton)
                    {
                        ((RadioButton)kvp.Value).Checked = (bool)value;
                    }
                    else if (kvp.Value is Panel)
                    {
                        RadioButton radio = kvp.Value.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Tag.Equals(value));
                        if (radio != null)
                        {
                            radio.Checked = true;
                        }
                        else
                        {
                            throw new Exception("No radio button matching value found");
                        }
                    }
                    else if (kvp.Value is ctrlTrackbar)
                    {
                        ((ctrlTrackbar)kvp.Value).Value = (int)(uint)value;
                    }
                    else if (kvp.Value is ctrlHorizontalTrackbar)
                    {
                        ((ctrlHorizontalTrackbar)kvp.Value).Value = (int)value;
                    }
                    else if (kvp.Value is TrackBar)
                    {
                        if (field.FieldType == typeof(Int32))
                        {
                            ((TrackBar)kvp.Value).Value = (int)value;
                        }
                        else
                        {
                            ((TrackBar)kvp.Value).Value = (int)(uint)value;
                        }
                    }
                    else if (kvp.Value is NumericUpDown)
                    {
                        NumericUpDown nud = kvp.Value as NumericUpDown;
                        decimal       val;
                        if (field.FieldType == typeof(UInt32))
                        {
                            val = (UInt32)value;
                        }
                        else if (field.FieldType == typeof(Int32))
                        {
                            val = (Int32)value;
                        }
                        else
                        {
                            val = (decimal)(double)value;
                        }
                        val       = Math.Min(Math.Max(val, nud.Minimum), nud.Maximum);
                        nud.Value = val;
                    }
                    else if (kvp.Value is ComboBox)
                    {
                        ComboBox combo = kvp.Value as ComboBox;
                        if (value is Enum)
                        {
                            combo.SelectedItem = ResourceHelper.GetEnumText((Enum)value);
                        }
                        else if (field.FieldType == typeof(UInt32))
                        {
                            for (int i = 0, len = combo.Items.Count; i < len; i++)
                            {
                                UInt32 numericValue;
                                string item = Regex.Replace(combo.Items[i].ToString(), "[^0-9]", "");
                                if (UInt32.TryParse(item, out numericValue))
                                {
                                    if (numericValue == (UInt32)value)
                                    {
                                        combo.SelectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                        else if (field.FieldType == typeof(string))
                        {
                            combo.SelectedItem = value;
                            if (combo.SelectedIndex < 0 && combo.Items.Count > 0)
                            {
                                combo.SelectedIndex = 0;
                            }
                        }
                    }
                }
            }

            this.Updating = false;

            this.AfterUpdateUI();
        }
Esempio n. 9
0
 private void picDonate_Click(object sender, EventArgs e)
 {
     Process.Start("http://www.mesen.ca/Donate.php?l=" + ResourceHelper.GetLanguageCode());
 }