Beispiel #1
0
        protected virtual void doWork(object sender, DoWorkEventArgs e) {
            ProgressHandler.state = ProgressState.Indeterminate;
            if (!initialized) {
                TranslatingProgressHandler.setTranslatedMessage("LoadingSettings");

                if (!settings.IsReady) {
                    initialized = false;
                    TranslatingMessageHandler.SendError("CriticalSettingsFailure");
                    return;
                }

                Core.locations.setup();

                settings.PropertyChanged += new PropertyChangedEventHandler(settings_PropertyChanged);

                monitor = new Monitor.Monitor();

                TranslatingProgressHandler.setTranslatedMessage("ValidatingBackupPath");
                if (settings.IsBackupPathSet && (!PermissionsHelper.isReadable(settings.backup_path) || !PermissionsHelper.isWritable(settings.backup_path)))
                    settings.clearBackupPath();

                if (!locations.ready)
                    return;

                //task = new Task.TaskHandler();

                initialized = true;
            }
            //ProgressHandler.progress_state = ProgressState.Normal;
        }
Beispiel #2
0
 private static void purgeRoots(object sender, DoWorkEventArgs e)
 {
     //            if (TranslatingRequestHandler.Request(RequestType.Question, "PurgeConfirmation").Cancelled) {
     //              e.Cancel = true;
     //            return;
     //      }
     ProgressHandler.saveMessage();
     e.Result = false;
     foreach (GameEntry game in (System.Collections.IEnumerable)e.Argument)
     {
         TranslatingProgressHandler.setTranslatedMessage("Purging", game.Title);
         try {
             if (game.purge(false))
             {
                 e.Result = true;
             }
             else
             {
                 break;
             }
         } catch (Exception ex) {
             TranslatingMessageHandler.SendError("PurgeError", ex, game.id.ToString());
         }
     }
     StaticNotifyPropertyChanged("HasUnsubmittedGames");
     ProgressHandler.restoreMessage();
 }
Beispiel #3
0
        protected override GameXmlFile ReadFile(FileInfo path) {
            bool keep_trying = true;
            while (keep_trying) {
                try {
                    if (path.Name == "custom.xml") {
                        this.custom = new CustomGameXmlFile(path);
                        return this.custom;
                    } else {
                        GameXmlFile file = new GameXmlFile(path);
                        return file;
                    }
                } catch (VersionNotSupportedException ex) {
                    if (ex.FileVersion == null || !GameSaveInfo.Converters.AConverter.CanConvert(ex.FileVersion)) {
                        string version_string;
                        if (ex.FileVersion == null)
                            version_string = Strings.GetLabelString("UnknownVersion");
                        else
                            version_string = ex.FileVersion.ToString();

                        if (!TranslatingRequestHandler.Request(MVC.Communication.RequestType.Question, "GameDataObsoleteDelete", path.Name, version_string).Cancelled) {
                            path.Delete();
                        }
                        keep_trying = false;
                    }
                } catch (XmlException ex) {
                    TranslatingMessageHandler.SendError("XMLFormatError", ex, path.FullName);
                    keep_trying = handleCorruptedFile(path);
                } catch (NotSupportedException ex) {
                    TranslatingMessageHandler.SendError("XMLFormatError", ex, path.FullName);
                    keep_trying = handleCorruptedFile(path);
                }
            }
            return null;
        }
        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.SaveFileDialog save = new System.Windows.Forms.SaveFileDialog();
            save.DefaultExt = "txt";
            save.Filter     = Strings.GetLabelString("TxtFileDescriptionPlural") + "|*.txt|" + Strings.GetLabelString("AllFileDescriptionPlural") + "|*";
            save.Title      = Strings.GetLabelString("SaveReportQuestion");

            if (AAnalyzer.LastSavePath == null)
            {
                save.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            }
            else
            {
                save.InitialDirectory = AAnalyzer.LastSavePath;
            }

            save.FileName = analyzer.game.Name + ".txt";
            if (save.ShowDialog(this.GetIWin32Window()) != System.Windows.Forms.DialogResult.Cancel)
            {
                AAnalyzer.LastSavePath = Path.GetDirectoryName(save.FileName);
                try {
                    StreamWriter writer = File.CreateText(save.FileName);
                    writer.Write(reportTxt.Text);
                    writer.Close();
                    saved = true;
                } catch (Exception ex) {
                    TranslatingMessageHandler.SendError("WriteError", ex, save.FileName);
                }
            }
        }
        public static void beginRestore(AViewWindow parent, List <Archive> archives)
        {
            string extrasave = ProgressHandler.message;

            ProgressHandler.saveMessage();
            parent.hideInterface();
            if (archives.Count > 1 && !TranslatingRequestHandler.Request(RequestType.Question, "RestoreMultipleArchives").Cancelled)
            {
                Restore.RestoreProgramHandler.use_defaults = true;
            }

            foreach (Archive archive in archives)
            {
                if (Restore.RestoreProgramHandler.overall_stop)
                {
                    break;
                }

                Restore.RestoreWindow restore = new Restore.RestoreWindow(archive, parent);
                restore.ShowDialog();

                switch (restore.Result)
                {
                case RestoreResult.Success:
                    Core.redetect_games = true;
                    break;

                case RestoreResult.Cancel:
                case RestoreResult.Failed:
                case RestoreResult.ElevationFailed:
                    break;
                }
            }
            Restore.RestoreProgramHandler.use_defaults = false;
            Restore.RestoreProgramHandler.overall_stop = false;
            // Restore.RestoreProgramHandler.default_user = null;
            if (Restore.RestoreProgramHandler.unsuccesfull_restores.Count > 0)
            {
                StringBuilder fail_list = new StringBuilder();
                foreach (string failed in Restore.RestoreProgramHandler.unsuccesfull_restores)
                {
                    fail_list.AppendLine(failed);
                }
                TranslatingMessageHandler.SendError("RestoreSomeFailed", fail_list.ToString());
            }
            parent.showInterface();
            ProgressHandler.message = extrasave;
        }
 void BackupProgramHandler_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     // Make this check for things errors so it can clean up after itself
     if (output_path == null)
     {
         return;
     }
     foreach (FileInfo delete_me in new DirectoryInfo(output_path).GetFiles("~*.tmp"))
     {
         try {
             delete_me.Delete();
         } catch (Exception ex) {
             TranslatingMessageHandler.SendError("DeleteError", ex, delete_me.Name);
         }
     }
 }
        private void beginRestoration()
        {
            if (flipper.IsActiveControl(selectFilesGroup))
            {
                if (files.SelectedItems.Count == 0)
                {
                    TranslatingMessageHandler.SendError("RestoreNoFiles");
                    return;
                }
            }

            TranslationHelpers.translate(this, "RestoringFile", restore.archive.id.ToString());
            restoreButton.Visibility     = System.Windows.Visibility.Collapsed;
            choosePathButton.Visibility  = System.Windows.Visibility.Collapsed;
            selectFilesButton.Visibility = System.Windows.Visibility.Collapsed;
            otherUserButton.Visibility   = System.Windows.Visibility.Collapsed;
            cancelButton.Text            = Strings.GetLabelString("Stop");

            flipper.SwitchControl(ProgressBox);

            if (Restore.RestoreProgramHandler.use_defaults && userCombo.SelectedItem != null)
            {
                //RestoreProgramHandler.default_user = (string)userCombo.SelectedItem;
            }


            if (files != null)
            {
                foreach (SelectFile file in files)
                {
                    if (file.IsSelected)
                    {
                        restore.specifyFileToRestore(file.name);
                    }
                }
            }
            restore.restoreBackup((LocationPath)pathCombo.SelectedItem, (string)userCombo.SelectedItem, restoreComplete);
        }
        void BackupProgramHandler_DoWork(object sender, DoWorkEventArgs e)
        {
            if (Core.settings.IsBackupPathSet || archive_name_override != null)
            {
                if (archive_name_override != null)
                {
                    output_path = Path.GetDirectoryName(archive_name_override);
                }
                else
                {
                    output_path = Core.settings.backup_path;
                }


                IList <GameEntry> games;

                if (back_these_up != null && back_these_up.Count > 0)
                {
                    games = back_these_up;
                }
                else
                {
                    if (Games.detected_games_count == 0)
                    {
                        Games.detectGames();
                    }
                    games = Games.DetectedGames.Items;
                }

                if (games.Count > 0)
                {
                    ProgressHandler.value = 1;
                    ProgressHandler.max   = games.Count;
                    TranslatingProgressHandler.setTranslatedMessage("GamesToBeBackedUpCount", games.Count.ToString());


                    foreach (GameEntry game in games)
                    {
                        if (CancellationPending)
                        {
                            return;
                        }

                        //if(archive_name_override!=null)
                        //all_users_archive = new ArchiveHandler(new FileInfo(archive_name_override),game.id);

                        if (games.Count == 1)
                        {
                            TranslatingProgressHandler.setTranslatedMessage("BackingUpSingleGame", game.Title);
                        }
                        else
                        {
                            TranslatingProgressHandler.setTranslatedMessage("BackingUpMultipleGames", game.Title, ProgressHandler.value.ToString(), games.Count.ToString());
                        }

                        List <DetectedFile> files;
                        if (only_these_files != null && only_these_files.Count > 0)
                        {
                            files = only_these_files;
                        }
                        else
                        {
                            files = game.Saves.Flatten();
                            ;
                        }


                        Archive override_archive = null;

                        try {
                            DictionaryList <Archive, DetectedFile> backup_files = new DictionaryList <Archive, DetectedFile>();
                            foreach (DetectedFile file in files)
                            {
                                ArchiveID archive_id;
                                Archive   archive;
                                if (CancellationPending)
                                {
                                    return;
                                }

                                archive_id = new ArchiveID(game.id, file);

                                if (archive_name_override != null)
                                {
                                    if (override_archive == null)
                                    {
                                        file.Type = null;
                                    }
                                    override_archive = new Archive(new FileInfo(archive_name_override), new ArchiveID(game.id, file));
                                    archive          = override_archive;
                                }
                                else
                                {
                                    if (Archives.Get(archive_id) == null)
                                    {
                                        Archives.Add(new Archive(output_path, new ArchiveID(game.id, file)));
                                    }
                                    archive = Archives.Get(archive_id);
                                }

                                backup_files.Add(archive, file);
                            }
                            if (CancellationPending)
                            {
                                return;
                            }

                            foreach (KeyValuePair <Archive, List <DetectedFile> > backup_file in backup_files)
                            {
                                if (override_archive == null)
                                {
                                    backup_file.Key.backup(backup_file.Value, false, false);
                                }
                                else
                                {
                                    backup_file.Key.backup(backup_file.Value, true, false);
                                }
                            }
                        } catch (Exception ex) {
                            TranslatingMessageHandler.SendException(ex);
                        } finally {
                            ProgressHandler.value++;
                        }
                    }
                }
                else
                {
                    TranslatingMessageHandler.SendError("NothingToBackup");
                }
            }
            else
            {
                TranslatingMessageHandler.SendError("BackupPathNotSet");
            }
        }
Beispiel #9
0
        private void add(string file, bool disable_versioning)
        {
            FileInfo TempFile = new FileInfo(TempFileName);

            if (TempFile.Exists)
            {
                TempFile.Delete();
            }


            if (this.Exists)
            {
                ArchiveFile.CopyTo(TempFileName);
                File.SetAttributes(TempFileName, FileAttributes.Hidden);
            }

            zipper.StartInfo.Arguments = compress_switches + " \"" + TempFileName + "\" \"" + file + "\\*\"";
            run7z(false);

            File.SetAttributes(TempFileName, FileAttributes.Hidden);

            // This here's the versioning stuff. Since it's here, it's universal.
            // This handles versioning copies
            if (!disable_versioning && Core.settings.VersioningEnabled)
            {
                if (Core.settings.VersioningMax != 0)
                {
                    DateTime right_now     = DateTime.Now;
                    FileInfo original_file = new FileInfo(file);
                    if (original_file.Exists)
                    {
                        if (right_now.Ticks - original_file.CreationTime.Ticks > Core.settings.VersioningTicks)
                        {
                            string new_path = Path.Combine(original_file.DirectoryName, Path.GetFileNameWithoutExtension(original_file.FullName) + "@" + right_now.ToString().Replace('/', '-').Replace(':', '-') + Path.GetExtension(original_file.FullName));
                            try {
                                File.Move(file, new_path);
                                //File.SetCreationTime(temp_file_name,right_now);
                            } catch (Exception ex) {
                                throw new TranslateableException("RevisionCopyError", ex, original_file.FullName);
                            }
                        }
                        else
                        {
                            // This is if it hasn't been long enough for a new file
                        }
                    }
                    else
                    {
                        // This shouldn't really be an error, as it just means that it's a new archive
                        //MessageHandler.SendError("Where'd That Come From?","The file " + file_name + " can't be found.");
                    }
                }
                else
                {
                    //this is if the Settings for versioning are f****d up
                }

                FileInfo[] count_us = new DirectoryInfo(Path.GetDirectoryName(file)).GetFiles(
                    Path.GetFileNameWithoutExtension(file) + "@*");


                if (count_us.Length > Core.settings.VersioningMax)
                {
                    Array.Sort(count_us, new MASGAU.Comparers.FileInfoComparer(true));
                    for (long i = Core.settings.VersioningMax; i < count_us.Length; i++)
                    {
                        try {
                            (count_us[i] as FileInfo).Delete();
                        } catch (Exception ex) {
                            TranslatingMessageHandler.SendError("DeleteError", ex, (count_us[i] as FileInfo).Name);
                        }
                    }
                }
            }
            else
            {
                // This is if versioning is disabled, or something
            }

            if (Exists)
            {
                ArchiveFile.Delete();
            }

            TempFile.MoveTo(ArchiveFile.FullName);
            File.SetAttributes(ArchiveFile.FullName, FileAttributes.Normal);
        }
Beispiel #10
0
        // This helps determin wether this is the first time the archive has been backed up to
        // it's so we can bypass the date checks as they will not be accurate anymore
        public void backup(ICollection <DetectedFile> files, bool disable_versioning, bool disable_date_check)
        {
            prepTemp();


            if (Exists)
            {
                if (!canWrite(ArchiveFile))
                {
                    throw new TranslateableException("WriteDenied", ArchiveFile.FullName);
                }
            }
            else
            {
                if (!canWrite(ArchiveFile.Directory))
                {
                    throw new TranslateableException("WriteDenied", ArchiveFile.DirectoryName);
                }

                // If this is the first time writing to the archive, we create the identifying XML
                XmlDocument write_me = new XmlDocument();
                if (File.Exists(Path.Combine(TempFolder, "masgau.xml")))
                {
                    File.Delete(Path.Combine(TempFolder, "masgau.xml"));
                }

                XmlTextWriter write_here = new XmlTextWriter(Path.Combine(TempFolder, "masgau.xml"), System.Text.Encoding.UTF8);
                write_here.Formatting = Formatting.Indented;
                write_here.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                write_here.WriteStartElement("masgau_archive");
                write_here.Close();
                write_me.Load(Path.Combine(TempFolder, "masgau.xml"));
                //XmlNode root = write_me.DocumentElement;

                id.AddElements(write_me);

                FileStream this_file = new FileStream(Path.Combine(TempFolder, "masgau.xml"), FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);

                write_me.Save(this_file);
                write_here.Close();
                this_file.Close();
            }
            bool files_added = false;

            foreach (DetectedFile file in files)
            {
                // Copies the particular file to a relative path inside the temp folder
                FileInfo source;
                FileInfo destination;
                if (file.Path == "" || file.Path == null)
                {
                    source      = new FileInfo(Path.Combine(file.AbsoluteRoot, file.Name));
                    destination = new FileInfo(Path.Combine(TempFolder, file.Name));
                }
                else
                {
                    source      = new FileInfo(Path.Combine(file.AbsoluteRoot, file.Path, file.Name));
                    destination = new FileInfo(Path.Combine(TempFolder, file.Path, file.Name));
                }

                if (!source.Exists)
                {
                    continue;
                }

                DateTime file_write_time = source.LastWriteTime;
                int      time_comparison = LastModified.CompareTo(source.LastWriteTime);

                if (Core.settings.IgnoreDateCheck || disable_date_check || time_comparison <= 0)
                {
                    try {
                        if (!destination.Directory.Exists)
                        {
                            destination.Directory.Create();
                        }
                    } catch (Exception e) {
                        TranslatingMessageHandler.SendError("CreateError", e, destination.DirectoryName);
                        continue;
                    }

                    if (source.Exists)
                    {
                        try {
                            source.CopyTo(destination.FullName, true);
                        } catch (Exception e) {
                            TranslatingMessageHandler.SendError("CopyError", e, source.FullName, destination.FullName);
                            continue;
                        }
                    }
                    else
                    {
                        TranslatingMessageHandler.SendError("FileToCopyNotFound", source.FullName);
                        continue;
                    }

                    if (destination.Exists)
                    {
                        try {
                            if ((destination.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                            {
                                File.SetAttributes(destination.FullName, FileAttributes.Normal);
                            }
                        } catch (Exception e) {
                            TranslatingMessageHandler.SendError("PermissionChangeError", e, destination.FullName);
                            continue;
                        }
                    }
                    else
                    {
                        TranslatingMessageHandler.SendError("FileCopiedNotFound", source.FullName, destination.FullName);
                        continue;
                    }
                    files_added = true;
                }
                //file_date = new FileInfo(file_name).LastWriteTime;
            }
            if (files_added)
            {
                add(TempFolder, disable_versioning);
            }

            purgeTemp();
        }
Beispiel #11
0
        public bool Detect()
        {
            //            detect_override =  rnd.Next(0, 2) == 0;

            List <DetectedLocationPathHolder> interim = new List <DetectedLocationPathHolder>();
            List <ALocation> locations = AllLocations;



            if (this.id.Name == "HalfLife2Deathmatch")
            {
                System.Console.Out.Write("");
            }

            foreach (ALocation location in locations)
            {
                // This skips if a location is marked as only being for a specific version of an OS
                if (location.OnlyFor != Core.locations.platform_version && location.OnlyFor != null)
                {
                    continue;
                }

                if (location.GetType() == typeof(LocationParent))
                {
                    // This checks all the locations that are based on other games
                    LocationParent game = location as LocationParent;
                    if (Games.Contains(game.game))
                    {
                        GameEntry parent_game = Games.Get(game.game);
                        // If the game hasn't been processed in the GamesHandler yetm it won't yield useful information, so we force it to process here
                        if (!parent_game.DetectionAttempted)
                        {
                            parent_game.Detect();
                        }
                        foreach (DetectedLocationPathHolder check_me in parent_game.DetectedLocations)
                        {
                            string path = location.modifyPath(check_me.FullDirPath);
                            interim.AddRange(Core.locations.interpretPath(path));
                        }
                    }
                    else
                    {
                        TranslatingMessageHandler.SendError("ParentGameDoesntExist", game.game.ToString());
                    }
                }
                else
                {
                    // This checks all the registry locations
                    // This checks all the shortcuts
                    // This parses each location supplied by the XML file
                    //if(title.StartsWith("Postal 2"))
                    //if(id.platform== GamePlatform.PS1)
                    interim.AddRange(Core.locations.getPaths(location));
                }
            }


            DetectedLocations = new Location.DetectedLocations();
            foreach (DetectedLocationPathHolder check_me in interim)
            {
                if (version.Identifiers.Count == 0)
                {
                    DetectedLocations.Add(check_me);
                    continue;
                }
                foreach (Identifier identifier in version.Identifiers)
                {
                    if (identifier.FindMatching(check_me.FullDirPath).Count > 0)
                    {
                        DetectedLocations.Add(check_me);
                        break;
                    }
                }
            }
            _detected_paths_string = new StringBuilder();

            foreach (DetectedLocationPathHolder location in DetectedLocations)
            {
                _detected_paths_string.AppendLine(location.FullDirPath);
            }

            NotifyPropertyChanged("IsDetected");
            NotifyPropertyChanged("IsMonitored");
            DetectionAttempted = true;

            return(IsDetected);
        }