Beispiel #1
0
        private void HandleSaveFailed(object sender, INTV.Shared.Model.Program.ProgramCollectionSaveFailedEventArgs e)
        {
            // FIXME: If this is ever invoked from a non-UI thread -- I'm looking at you, Mac, it may be trouble.
            var title   = Resources.Strings.RomList_SaveFailed_Title;
            var message = Resources.Strings.RomList_SaveFailed_Message;
            var buttons = OSMessageBoxButton.OK;

            if (!string.IsNullOrEmpty(e.RomListBackupPath) && System.IO.File.Exists(e.RomListBackupPath))
            {
                message += Resources.Strings.RomList_SaveFailed_PromptToRestoreMessage;
                buttons  = OSMessageBoxButton.YesNo;
            }
            var result = OSMessageBox.Show(message, title, e.Error, buttons, OSMessageBoxIcon.Error);

            if ((result == OSMessageBoxResult.Yes) && !string.IsNullOrEmpty(e.RomListBackupPath) && System.IO.File.Exists(e.RomListBackupPath))
            {
                var romsConfiguration = INTV.Shared.Model.RomListConfiguration.Instance;
                System.IO.File.Replace(e.RomListPath, romsConfiguration.RomFilesPath, null);
                InitializeRomList(romsConfiguration.RomFilesPath);
            }
        }
Beispiel #2
0
        public void Save(string filePath, bool handleErrorIfPossible)
        {
            var path       = string.Intern(filePath);
            var backupPath = path.GetUniqueBackupFilePath();

            try
            {
                lock (path)
                {
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Copy(path, backupPath); // back up the current file
                    }
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        var serializer = new System.Xml.Serialization.XmlSerializer(typeof(Program.ProgramCollection));
                        serializer.Serialize(fileStream, this);
                    }
                    if (!string.IsNullOrEmpty(backupPath) && System.IO.File.Exists(backupPath))
                    {
                        FileUtilities.DeleteFile(backupPath, false, 10);
                    }
                }
            }
            catch (Exception error)
            {
                var saveFailed = SaveFailed;
                if (handleErrorIfPossible && (saveFailed != null))
                {
                    var saveFailedArgs = new ProgramCollectionSaveFailedEventArgs(path, error, backupPath);
                    saveFailed(this, saveFailedArgs);
                }
                else
                {
                    throw;
                }
            }
        }