コード例 #1
0
 public OverviewDetails(ManagedGameVersion versionItem, Overview parent)
 {
     GameDetails = versionItem;
     _parent     = parent;
     InitializeComponent();
     DataContext = this;
 }
コード例 #2
0
        public void DeleteGameDirectory(ManagedGameVersion game, IProgress <int> progress)
        {
            progress.Report(10);
            if (Directory.Exists(game.Path))
            {
                Directory.Delete(game.Path, true);
            }

            RootDirectoryEntity        root          = new RootDirectoryEntityIO().Deserialize(game.GameXML);
            List <RootDirectoryEntity> otherVersions = new List <RootDirectoryEntity>();

            foreach (var mgv in _mvs.GetManagedVersions())
            {
                RootDirectoryEntity data = new RootDirectoryEntityIO().Deserialize(mgv.GameXML);
                otherVersions.Add(data);
            }

            Progress <int> partialProgress = new Progress <int>(prog =>
            {
                int percent = (int)(prog * 0.9);
                progress.Report(10 + percent);
            });

            string container = Settings.Default.ContainerDirectory;

            GameFilesRemover.RemoveFiles(root, otherVersions, Helpers.EntityToPath(container), _dirCache, partialProgress);
            SaveDirCache();

            System.Windows.Application.Current.Dispatcher.BeginInvoke((Action) delegate()
            {
                _mvs.Remove(game);
            });
            progress.Report(100);
        }
コード例 #3
0
        public async void RebuildDirectory(ManagedGameVersion version)
        {
            ProgressWindow pw = new ProgressWindow("Verify integrity", "Rebuilding World of Tanks directory. Do not close the application.");

            pw.CloseOnComplete = true;
            var winTask = pw.ShowDialogAsync();

            int            previous = 0;
            Progress <int> progress = new Progress <int>(prog =>
            {
                if (prog != previous)
                {
                    pw.SetProgress(prog);
                }
                previous = prog;
            });

            try
            {
                await Task.Run(() => _gameDirService.RebuildGameDirectory(version, progress));
            }
            catch (FileNotFoundException ex)
            {
                new MessageWindow("Error", "Corrupted files detected. Please delete this version and re-import it.", MessageWindowButtons.OK).ShowDialog();
                (progress as IProgress <int>).Report(100);
            }
            await winTask;
        }
コード例 #4
0
 public void Remove(ManagedGameVersion game)
 {
     if (_items.Contains(game))
     {
         _items.Remove(game);
         Save();
     }
 }
コード例 #5
0
        public void UpdateGameDirectory(RootDirectoryEntity updated, string outputDir, IProgress <int> progress)
        {
            ManagedGameVersion   oldMGV        = _mvs.GetManagedVersions().First(mvg => mvg.Version == updated.Version);
            RootDirectoryEntity  oldBuild      = new RootDirectoryEntityIO().Deserialize(oldMGV.GameXML);
            HashSet <FileEntity> oldFiles      = oldBuild.GetAllFileEntities(true).OfType <FileEntity>().ToHashSet();
            HashSet <FileEntity> newFiles      = updated.GetAllFileEntities(true).OfType <FileEntity>().ToHashSet();
            HashSet <FileEntity> changedFiles  = newFiles.Except(oldFiles).ToHashSet();
            HashSet <FileEntity> filesToRemove = oldFiles.Except(newFiles).ToHashSet();

            // Do not remove files that only changed location
            HashSet <string>     newFilesHashes  = newFiles.Select(x => x.Hash).ToHashSet();
            HashSet <FileEntity> movedFileHashes = filesToRemove.Where(f => newFilesHashes.Contains(f.Hash)).ToHashSet();

            filesToRemove.ExceptWith(movedFileHashes);

            string container = Settings.Default.ContainerDirectory;
            List <RootDirectoryEntity> otherVersions = new List <RootDirectoryEntity>();

            foreach (var mgv in _mvs.GetManagedVersions().Except(new List <ManagedGameVersion>()
            {
                oldMGV
            }))
            {
                RootDirectoryEntity data = new RootDirectoryEntityIO().Deserialize(mgv.GameXML);
                otherVersions.Add(data);
            }

            int            basePercent     = 0;
            Progress <int> partialProgress = new Progress <int>(percent =>
            {
                progress.Report(basePercent + percent / 2);
            });

            // Remove old unused files from cache
            GameFilesRemover.RemoveFiles(filesToRemove,
                                         otherVersions,
                                         Helpers.EntityToPath(container),
                                         _dirCache,
                                         partialProgress
                                         );
            SaveDirCache();
            basePercent = 50;
            // Remove old unused files from game directory
            foreach (FileEntity unusedFile in filesToRemove)
            {
                string path = Path.Combine(oldMGV.Path, unusedFile.RelativePath);
                try
                {
                    File.Delete(path);
                }
                catch (Exception ex) { }
            }

            // Update files in directory
            CreateGameDirectory(updated, oldMGV.Path, partialProgress);
            progress.Report(100);
        }
コード例 #6
0
        private void btnRemove_Click(object sender, RoutedEventArgs e)
        {
            ManagedGameVersion version = lbVersions.SelectedItem as ManagedGameVersion;

            if (version != null)
            {
                ManagedVersions.Remove(version);
            }
        }
コード例 #7
0
        private async void RemoveGameFiles()
        {
            string             btnContent = btnRemove.Content as string;
            ManagedGameVersion selected   = lbVersions.SelectedItem as ManagedGameVersion;

            if (selected == null)
            {
                return;
            }

            _containerPath = txtContainer.Text;
            if (_containerPath == null || !Directory.Exists(_containerPath))
            {
                MessageBox.Show("Please select container directory.", "Error");
                return;
            }

            if (!LoadDirCache())
            {
                return;
            }

            MessageBoxResult result = MessageBox.Show("This process will remove ALL files from the selected version and delete the game directory. Proceed?", "Warning", MessageBoxButton.YesNo);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }

            btnRemove.IsEnabled = false;
            btnRemove.Content   = "Removing...";

            if (Directory.Exists(selected.Path))
            {
                await Task.Run(() => Directory.Delete(selected.Path, true));
            }

            RootDirectoryEntity        root          = new RootDirectoryEntityIO().Deserialize(selected.GameXML);
            List <RootDirectoryEntity> otherVersions = new List <RootDirectoryEntity>();

            foreach (var mgv in ManagedVersions)
            {
                RootDirectoryEntity data = new RootDirectoryEntityIO().Deserialize(mgv.GameXML);
                otherVersions.Add(data);
            }

            await Task.Run(() => GameFilesRemover.RemoveFiles(root, otherVersions, _containerPath, Helpers.EntityToPath(_containerPath), _dirCache, null));

            ManagedVersions.Remove(selected);
            SaveManagedVersions();
            SaveDirCache();

            btnRemove.IsEnabled = true;
            btnRemove.Content   = btnContent;
        }
コード例 #8
0
        public void RebuildGameDirectory(ManagedGameVersion game, IProgress <int> progress)
        {
            progress.Report(10);
            if (Directory.Exists(game.Path))
            {
                Directory.Delete(game.Path, true);
            }

            Progress <int> partialProgress = new Progress <int>(percent =>
            {
                progress.Report((int)(10 + 0.9 * percent));
            });

            CreateGameDirectory(game.GameXML, game.Path, partialProgress);
            progress.Report(100);
        }
コード例 #9
0
        public async void DeleteVersion(ManagedGameVersion version)
        {
            ProgressWindow pw = new ProgressWindow("Deleting version", "Deleting selected World of Tanks version. Do not close the application.");

            pw.CloseOnComplete = true;
            var winTask = pw.ShowDialogAsync();

            int            previous = 0;
            Progress <int> progress = new Progress <int>(prog =>
            {
                if (prog != previous)
                {
                    pw.SetProgress(prog);
                }
                previous = prog;
            });
            await Task.Run(() => _gameDirService.DeleteGameDirectory(version, progress));

            await winTask;
        }
コード例 #10
0
 public void Add(ManagedGameVersion mgv)
 {
     _items.Add(mgv);
     Save();
 }
コード例 #11
0
 public bool Contains(ManagedGameVersion version)
 {
     return(_items.Contains(version));
 }