/// <summary> /// Set globals, get data from LB, and set controls. /// </summary> private void InitManager() { LaunchBoxInstallFolder = AppDomain.CurrentDomain.BaseDirectory; LaunchBoxPluginsFolder = $@"{LaunchBoxInstallFolder}Plugins\TBPM\"; PluginTempFolder = $@"{LaunchBoxPluginsFolder}t\"; if (PluginHelper.DataManager != null) { List <IEmulator> emulators = PluginHelper.DataManager.GetAllEmulators().ToList(); emulator = emulators.Find(e => e.ApplicationPath.ToLower().Contains("retroarch.exe")); } txtRetroInstallationFolder.BackColor = DefaultBackColor; EmulatorInstallPath = (emulator != null) ? emulator.ApplicationPath : "Please configure Retroarch in LaunchBox before continuing."; int i = EmulatorInstallPath.LastIndexOf(Path.DirectorySeparatorChar); if (i > 0) { EmulatorInstallPath = EmulatorInstallPath.Substring(0, i); txtRetroInstallationFolder.ForeColor = System.Drawing.Color.Black; } else { txtRetroInstallationFolder.ForeColor = System.Drawing.Color.Red; #if DEBUG EmulatorInstallPath = @"E:\Games\Emulation\LaunchBox\Emulators\RetroArch\"; #endif } txtRetroInstallationFolder.Text = EmulatorInstallPath; Directory.CreateDirectory(PluginTempFolder); SupportedSystemData = BezelManagerHelper.GetBezelData(Path.Combine(LaunchBoxPluginsFolder, "BezelManagerSupportedSystems.json")); SelectedBezel = new SelectedBezelData(); foreach (var item in SupportedSystemData.Systems.System) { this.cbSystemList.Items.Add(item.SystemName); } pbProgressStatus.Maximum = 100; pbProgressStatus.Step = 1; pbProgressStatus.MarqueeAnimationSpeed = 25; progressInfo = new Progress <ProgressInfo>(info => { pbProgressStatus.Style = (info.ProgressValue > 0) ? ProgressBarStyle.Continuous : ProgressBarStyle.Marquee; pbProgressStatus.Value = info.ProgressValue; lblProgessStatus.Text = info.ProgressStatus; }); DisableButtons(); toolTip.SetToolTip(this.btnInstallBezel, "Downloads and processes selected Bezel package."); toolTip.SetToolTip(this.chkKeepMasterFile, "Zip file(s) will be located in the 't' folder inside the plugin folder."); toolTip.SetToolTip(this.btnCancel, "Cancels Bezel installation process."); }
/// <summary> /// Copy config and png files to the retroarch directories based on core selected (core game override files). /// </summary> /// <param name="progress"></param> /// <param name="packageName"></param> /// <param name="token"></param> /// <returns></returns> private Task <bool> CopyBezelFiles(IProgress <ProgressInfo> progress, Platform selectedPlatform, Core selectedCore, CancellationToken token) { try { var bezelRootDir = (chkSystemArt.Checked) ? "{0}bezelprojectSA-{1}-master" : "{0}bezelproject-{1}-master"; string rootDirectory = string.Format(bezelRootDir, PluginTempFolder, selectedPlatform.RepositoryName); string emuOverlayPath = string.Empty; if (!token.IsCancellationRequested) { DirectoryInfo rootFolder = new DirectoryInfo(rootDirectory); if (!rootFolder.Exists) { throw new DirectoryNotFoundException( "Unpacked content directory does not exist or could not be found: " + rootDirectory); } int TotalNumberOfFiles = 0; int ProcessedFile = 0; string emuCfgPath = Path.Combine($@"{EmulatorInstallPath}\config", selectedCore.ConfigFolder); Directory.CreateDirectory(emuCfgPath); // Bugfix for ArcadeBezels folder if (selectedPlatform.RepositoryName.Equals("MAME")) { emuOverlayPath = Path.Combine($@"{EmulatorInstallPath}\overlays\ArcadeBezels"); } else { emuOverlayPath = Path.Combine($@"{EmulatorInstallPath}\overlays\GameBezels", selectedPlatform.BezelFolder); } Directory.CreateDirectory(emuOverlayPath); // find the config and overlay folders. // there can be multiple folders for the different cores. We just want one, since all cfg files are the same. DirectoryInfo configFolder = rootFolder.GetDirectories("*", SearchOption.AllDirectories) .Where(d => d.Parent.Name.ToLower().Equals("config")) .FirstOrDefault(); DirectoryInfo overlayFolder = rootFolder.GetDirectories("*", SearchOption.AllDirectories) .Where(d => d.Name.ToLower().Equals("overlay")) .FirstOrDefault(); if (configFolder == null) { throw new Exception(string.Format("No config folder found in {0} package!", selectedPlatform.RepositoryName)); } if (overlayFolder == null) { throw new Exception(string.Format("No overlay folder found in {0} package!", selectedPlatform.RepositoryName)); } List <FileInfo> ConfigFiles = configFolder.GetFiles("*.*", SearchOption.AllDirectories) .Where(f => f.Name.EndsWith(".cfg", StringComparison.OrdinalIgnoreCase)) .ToList(); List <FileInfo> OverlayFiles = overlayFolder.GetFiles("*.*", SearchOption.AllDirectories) .Where(f => f.Name.EndsWith(".cfg", StringComparison.OrdinalIgnoreCase) || f.Name.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) .ToList(); if (ConfigFiles.Count == 0) { throw new Exception(string.Format("No config files found in {0} package!", selectedPlatform.RepositoryName)); } if (OverlayFiles.Count == 0) { throw new Exception(string.Format("No overlay files found in {0} package!", selectedPlatform.RepositoryName)); } TotalNumberOfFiles = ConfigFiles.Count() + OverlayFiles.Count(); ParallelOptions options = new ParallelOptions { CancellationToken = token, MaxDegreeOfParallelism = 2 }; // now copy files to the Retroarch locations. Parallel.ForEach(ConfigFiles, options, ConfigFile => { token.ThrowIfCancellationRequested(); ConfigFile.CopyTo(Path.Combine(emuCfgPath, ConfigFile.Name), true); progress?.Report(new ProgressInfo() { ProgressValue = (ProcessedFile++ *100 / TotalNumberOfFiles), ProgressStatus = string.Format("[{0}/{1}] Copying configs: {2}", ProcessedFile, TotalNumberOfFiles, ConfigFile.Name) }); }); Parallel.ForEach(OverlayFiles, options, ConfigFile => { token.ThrowIfCancellationRequested(); ConfigFile.CopyTo(Path.Combine(emuOverlayPath, ConfigFile.Name), true); progress?.Report(new ProgressInfo() { ProgressValue = (ProcessedFile++ *100 / TotalNumberOfFiles), ProgressStatus = string.Format("[{0}/{1}] Copying overlays: {2}", ProcessedFile, TotalNumberOfFiles, ConfigFile.Name) }); }); // Create core override config file. // Backup existing one for manual restore. // Find the system core config file if there is one. // If there is no game overlay, display system overlay as a sub // May add user selection to enable/disable this function in the future. if (true) { FileInfo file = OverlayFiles.Where(o => o.Directory.Name.ToLower().Equals("overlay") && o.Extension.Equals(".cfg")).FirstOrDefault(); string coreCfgPath = Path.Combine(emuCfgPath, selectedCore.ConfigFolder + ".cfg"); string coreCfgBackUp = Path.Combine(emuCfgPath, selectedCore.ConfigFolder + ".bak"); if (file != null) { if (File.Exists(coreCfgPath)) { // make backup if (File.Exists(coreCfgBackUp)) { File.Delete(coreCfgBackUp); } File.Copy(coreCfgPath, coreCfgBackUp); } File.WriteAllText(coreCfgPath, BezelManagerHelper.GenerateNewCoreOverride(selectedPlatform, file.Name)); } } ConfigFiles.Clear(); OverlayFiles.Clear(); return(Task.FromResult(true)); } return(Task.FromResult(false)); } catch (OperationCanceledException oce) { throw oce; } catch (Exception) { throw; } }