/// <summary> /// Initializes a new instance of the <see cref="INTV.Intellicart.Model.DownloadTaskData"/> class. /// </summary> /// <param name="task">The asynchronous task that will use this data.</param> /// <param name="intellicart">The Intellicart model to which a ROM is sent.</param> /// <param name="name">The name of the ROM being sent.</param> /// <param name="rom">The ROM being sent to an Intellicart.</param> internal DownloadTaskData(AsyncTaskWithProgress task, IntellicartModel intellicart, string name, IRom rom) : base(task) { Intellicart = intellicart; Name = name; Rom = rom; }
public SaveMenuLayoutTaskData(AsyncTaskWithProgress task, MenuLayout menuLayout, string path, bool nonDirtying) : base(task) { lock (menuLayout.FileSystem) { if (!string.IsNullOrEmpty(path) && System.IO.File.Exists(path)) { var menuPath = string.Intern(path); lock (menuPath) { BackupPath = path.GetUniqueBackupFilePath(); System.IO.File.Copy(path, BackupPath); } } } OriginalMenuLayout = menuLayout; SaveGeneration = menuLayout.SaveGeneration; if (menuLayout.FileSystem.Origin == FileSystemOrigin.HostComputer) { MenuLayoutToSave = menuLayout.FileSystem.Clone().Directories[GlobalDirectoryTable.RootDirectoryNumber] as MenuLayout; MenuLayoutToSave.FileSystem.Frozen = true; #if MEASURE_SAVE_PERFORMANCE MenuLayoutToSave.SaveGeneration = menuLayout.SaveGeneration; #endif // MEASURE_SAVE_PERFORMANCE } else { MenuLayoutToSave = menuLayout; } Path = path; NonDirtying = nonDirtying; }
/// <summary> /// Adds items to the given menu layout in which each items specifies its own destination directory. /// </summary> /// <param name="menuLayout">The menu layout to which items are to be added.</param> /// <param name="destinationDirectories">The destination directories to contain the added items.</param> /// <param name="items">The items to add.</param> internal static void AddItems(MenuLayoutViewModel menuLayout, IEnumerable <string> destinationDirectories, IEnumerable <ProgramDescription> items) { var taskData = new AddRomsToMenuData(menuLayout, destinationDirectories, items); var addRomsTask = new AsyncTaskWithProgress(Resources.Strings.AddItems_ProgressTitle, true, false); addRomsTask.RunTask(taskData, AddItems, AddItemsComplete); }
/// <summary> /// Add items to a specific destination folder. /// </summary> /// <param name="menuLayout">The menu layout to add items to.</param> /// <param name="destination">The folder to which items are to be added.</param> /// <param name="items">The items to add.</param> /// <param name="insertIndex">The location at which to insert the new items.</param> internal static void AddItems(MenuLayoutViewModel menuLayout, IFileContainer destination, IEnumerable <ProgramDescription> items, int insertIndex) { var taskData = new AddRomsToMenuData(menuLayout, destination, items, insertIndex); var addRomsTask = new AsyncTaskWithProgress(Resources.Strings.AddItems_ProgressTitle, true, false); addRomsTask.RunTask(taskData, AddItems, AddItemsComplete); }
/// <summary> /// Downloads a ROM to an Intellicart. /// </summary> /// <param name="intellicart">The Intellicart to load the ROM onto.</param> /// <param name="programName">Name of the program being downloaded.</param> /// <param name="rom">The ROM to load.</param> /// <param name="errorHandler">Error handler function.</param> public static void DownloadRom(this IntellicartModel intellicart, string programName, IRom rom, Action <string, Exception> errorHandler) { var title = string.Format(CultureInfo.CurrentCulture, Resources.Strings.DownloadRom_Title_Format, programName); var task = new AsyncTaskWithProgress(title, true, true, 0); var taskData = new DownloadTaskData(task, intellicart, programName, rom); taskData.ErrorHandler = errorHandler; task.RunTask(taskData, DownloadRom, DownloadRomComplete); }
/// <summary> /// Initializes a new instance of the /// <see cref="INTV.Shared.Commands.ApplicationCommandGroup+CheckForUpdatesTaskData"/> class. /// </summary> /// <param name="task">The task that executes.</param> /// <param name="checkingAtStartup">Set to <c>true</c> if we're checking for updates at application startup.</param> internal CheckForUpdatesTaskData(AsyncTaskWithProgress task, bool checkingAtStartup) : base(task) { CheckingAtStartup = checkingAtStartup; var entryAssembly = System.Reflection.Assembly.GetEntryAssembly(); VersionString = System.Diagnostics.FileVersionInfo.GetVersionInfo(entryAssembly.Location).FileVersion; Version = new System.Version(VersionString); }
/// <summary> /// Creates an asynchronous task using this data and starts it. A progress bar will appear after the specified amount of time passes. /// </summary> /// <param name="doWork">The actual work to execute in the asynchronous task.</param> /// <param name="allowsCancel">If <c>true</c>, allow the operation to be cancelled.</param> /// <param name="progressBarDelayTime">How long to wait (in seconds) before the progress bar appears.</param> public void StartTask(Action <AsyncTaskData> doWork, bool allowsCancel, double progressBarDelayTime) { var taskName = GetTitleForUpdate(); var executeCommandTask = new AsyncTaskWithProgress(taskName, allowsCancel, true, progressBarDelayTime); #if REPORT_COMMAND_PERFORMANCE DoWorkMethodName = doWork.Method.Name; DebugOutput(Device.Port.Name + ": DEVICECOMMAND START: " + DoWorkMethodName); Stopwatch = System.Diagnostics.Stopwatch.StartNew(); #endif // REPORT_COMMAND_PERFORMANCE executeCommandTask.RunTask(this, (d) => SyncWithTimerThenExecute(d, doWork), OnComplete); }
private static void ValidateRoms(object parameter) { var romListViewModel = parameter as RomListViewModel; if (romListViewModel != null) { var validateRomsTask = new AsyncTaskWithProgress("ValidateRoms", false, false); validateRomsTask.UpdateTaskTitle(Resources.Strings.ValidateRomsCommand_ProgressTitle); var validateRomsTaskData = new ValidateRomsTaskData(validateRomsTask, romListViewModel); validateRomsTask.RunTask(validateRomsTaskData, ValidateRoms, ValidateRomsComplete); } }
private static void OnCheckForUpdates(object parameter) { if (CanCheckForUpdates(parameter)) { var checkingAtStartup = false; if ((parameter != null) && (parameter.GetType() == typeof(bool))) { checkingAtStartup = (bool)parameter; } var checkForUpdatesTask = new AsyncTaskWithProgress("CheckForUpdates", false, true, !checkingAtStartup, 2); checkForUpdatesTask.UpdateTaskTitle(CheckForUpdatesCommand.Name); var checkForUpdatesTaskData = new CheckForUpdatesTaskData(checkForUpdatesTask, checkingAtStartup); checkForUpdatesTask.RunTask(checkForUpdatesTaskData, CheckForUpdates, CheckForUpdatesComplete); } }
private void AddPrograms(RomDiscoveryData taskData) { var cancel = Model.BeginAddRomsFromFiles(taskData.AddingStarterRoms); if (!cancel) { var gatherRomsTask = new AsyncTaskWithProgress(taskData.Title, true, true); gatherRomsTask.RunTask(taskData, GatherRoms, GatherRomsComplete); // EndAddRomsFromFiles is called in GatherRomsComplete(). } else { Model.EndAddRomsFromFiles(Enumerable.Empty <string>()); } }
/// <summary> /// Save the menu layout to a specific path. /// </summary> /// <param name="path">The absolute path of the file to save.</param> /// <param name="nonDirtying">If <c>true</c>, indicates save was not due to user edits, but some other operation.</param> internal void Save(string path, bool nonDirtying) { SaveMenuLayoutTaskData existingSave; if (!_saveTasks.TryGetValue(SaveGeneration, out existingSave)) { var saveMenuTask = new AsyncTaskWithProgress("SaveMenuLayout", true); // does not show progress var saveTaskData = new SaveMenuLayoutTaskData(saveMenuTask, this, path, nonDirtying); DebugMessage("Save BEGIN " + path + " GENERATION " + SaveGeneration); _saveTasks[SaveGeneration] = saveTaskData; saveMenuTask.RunTask(saveTaskData, Save, SaveComplete); } else { DebugMessage("Save ALREADY CREATED for " + path + " GENERATION " + SaveGeneration); } }
private void HideProgressIndicator(object sender, EventArgs e) { _cancelled = false; _launchTime = DateTime.MinValue; IsVisible = false; if (_timer != null) { _timer.Stop(); } _timer = null; _task = null; var application = SingleInstanceApplication.Instance; if ((application != null) && (application.MainWindow != null)) { PlatformOnHide(application); } CommandManager.InvalidateRequerySuggested(); }
private static void OnRestoreRomList(object parameter) { var configuration = INTV.Shared.Model.RomListConfiguration.Instance; var message = Resources.Strings.RestoreRomListCommand_Message; var title = Resources.Strings.RestoreRomListCommand_MessageTitle; var doRestore = OSMessageBox.Show(message, title, OSMessageBoxButton.YesNo, OSMessageBoxIcon.Exclamation); if (doRestore == OSMessageBoxResult.Yes) { var backupDirectory = configuration.BackupDataDirectory; var backupFileName = INTV.Shared.Model.RomListConfiguration.Instance.DefaultRomsFileName; var selectBackupDialog = SelectBackupDialog.Create(backupDirectory, backupFileName, null, false); selectBackupDialog.Title = Resources.Strings.RestoreRomListCommand_SelectBackupTitle; var doRestoreResult = selectBackupDialog.ShowDialog(); if (doRestoreResult == true) { var romsConfiguration = INTV.Shared.Model.RomListConfiguration.Instance; var backupRomListFile = System.IO.Path.Combine(selectBackupDialog.SelectedBackupDirectory, romsConfiguration.DefaultRomsFileName); var romsFileExists = System.IO.File.Exists(backupRomListFile); if (romsFileExists) { var restoreRomListTask = new AsyncTaskWithProgress("RestoreRomList", false, true, 0); restoreRomListTask.UpdateTaskTitle(Resources.Strings.RestoreRomListCommand_MessageTitle); var restoreMenuLayoutTaskData = new RestoreRomListTaskData(restoreRomListTask, backupRomListFile, parameter as RomListViewModel); restoreRomListTask.RunTask(restoreMenuLayoutTaskData, RestoreRomList, RestoreRomListComplete); } else { var errorMessage = new System.Text.StringBuilder(Resources.Strings.RestoreRomListCommand_MissingFileErrorMessage).AppendLine().AppendLine(); errorMessage.AppendLine(selectBackupDialog.SelectedBackupDirectory).AppendLine(); if (!romsFileExists) { errorMessage.AppendLine(romsConfiguration.DefaultRomsFileName); } message = errorMessage.ToString(); title = Resources.Strings.RestoreRomListCommand_MissingFileErrorTitle; OSMessageBox.Show(message, title, OSMessageBoxButton.OK, OSMessageBoxIcon.Error); } } } }
/// <summary> /// Instructs the progress indicator that it should display itself. It will appear after a brief delay. /// </summary> /// <param name="task">The task associated with the progress indicator.</param> /// <remarks>The progress indicator will display after a brief delay, and will display for a minimum amount of time once shown. /// If a task completes quickly, this prevents the progress indicator from appearing only to disappear almost instantaneously. /// Similarly, once the indicator becomes visible, it will remain visible for a minimum amount of time so as to be less jarring.</remarks> public void Show(AsyncTaskWithProgress task) { var application = SingleInstanceApplication.Instance; if (application != null) { application.IsBusy = true; _task = task; _cancelled = false; if (!IsVisible && (_timer == null) && (DisplayDelay > 0)) { PlatformOnShow(application); _timer = new OSDispatcherTimer(); _timer.Tick += ShowProgressIndicator; _timer.Interval = TimeSpan.FromSeconds(DisplayDelay); _timer.Start(); } else if (!(DisplayDelay < 0)) { PlatformOnShow(application); ShowProgressIndicator(this, EventArgs.Empty); } } }
/// <summary> /// Mac-specific error handler. /// </summary> /// <param name="emulator">The emulator instance that was running.</param> /// <param name="message">The error message.</param> /// <param name="exitCode">The exit code of the emulator.</param> /// <param name="exception">The exception that occurred.</param> static partial void OSErrorHandler(Emulator emulator, string message, int exitCode, Exception exception) { if (IsSDLMissingError(exitCode)) { var sdlVersionInfo = IncludedSDLVersion; var errorMessage = string.Format(CultureInfo.CurrentCulture, Resources.Strings.SDLNotFound_ErrorMessage, sdlVersionInfo.Version); // Check to see if we can determine the missing SDL version from the error message. // If the missing version is not the same as the included version, we must get the "other" version. // Also, check to see if we already have the included SDL installed. If we do, but the failure still indicates // that it's missing, then it's possible the version of jzIntv being run requires the "other" version of SDL. // Switch over to the 'other' version for reporting the error if such is the case. var missingVersion = GetMissingSDLVersionFromErrorMessage(message); if ((missingVersion != SDLVersion.Unknown) && (missingVersion != IncludedSDLVersion.Version) || sdlVersionInfo.IsAlreadyInstalled) { sdlVersionInfo = sdlVersionInfo.GetOtherSDLVersionInfo(); errorMessage = string.Format( CultureInfo.CurrentCulture, Resources.Strings.SDLNotFound_DownloadMissingVersion_Format, sdlVersionInfo.Version, sdlVersionInfo.VersionNumber, sdlVersionInfo.DownloadUrl); } var errorTitle = string.Format(CultureInfo.CurrentCulture, Resources.Strings.SDLNotFound_ErrorTitle, sdlVersionInfo.Version); if (OSMessageBox.Show(errorMessage, errorTitle, OSMessageBoxButton.YesNo) == OSMessageBoxResult.Yes) { var installSDLTask = new AsyncTaskWithProgress("InstallSDL", allowsCancel: false, isIndeterminate: true, progressDisplayDelay: 0); var installTitle = string.Format(CultureInfo.CurrentCulture, Resources.Strings.SDLInstall_Title, sdlVersionInfo.Version); installSDLTask.UpdateTaskTitle(installTitle); var installSDLTaskData = new InstallSDLTaskData(installSDLTask, sdlVersionInfo); installSDLTask.RunTask(installSDLTaskData, InstallSDL, InstallSDLComplete); } } }
/// <summary> /// Starts the search for devices. /// </summary> public void Start() { var task = new AsyncTaskWithProgress(Resources.Strings.DeviceSearch_Task_Title, true, true, 1.0); task.RunTask(this, CheckDevices, OnComplete); }
/// <summary> /// Initializes a new instance of the /// <see cref="INTV.Shared.Commands.RomListCommandGroup+RestoreRomListTaskData"/> class. /// </summary> /// <param name="task">The asynchronous task to execute the action.</param> /// <param name="fileToRestore">The ROM list backup file to restore.</param> /// <param name="romListViewModel">The ViewModel to inform of the restoration when complete.</param> internal RestoreRomListTaskData(AsyncTaskWithProgress task, string fileToRestore, RomListViewModel romListViewModel) : base(task) { FileToRestore = fileToRestore; RomListViewModel = romListViewModel; }
/// <summary> /// Initializes a new instance of ValidateRomsTaskData. /// </summary> /// <param name="task">The task that executes, using an instance of this type as data.</param> /// <param name="romListViewModel">The ROM list ViewModel being refreshed.</param> internal ValidateRomsTaskData(AsyncTaskWithProgress task, RomListViewModel romListViewModel) : base(task) { RomListViewModel = romListViewModel; UpdatedRoms = new List <INTV.Core.Model.Program.ProgramDescription>(); }
/// <summary> /// Initializes a new instance of the <see cref="InstallSDLTaskData"/> class. /// </summary> /// <param name="task">The installation task.</param> /// <param name="diskImageInfo">Description of the SDL disk image.</param> internal InstallSDLTaskData(AsyncTaskWithProgress task, SDLDiskImageInfo diskImageInfo) : base(task) { DiskImageInfo = diskImageInfo; }