Exemplo n.º 1
0
        private async Task loadUpkFile(FileViewEntity file, DomainUpkFile upkFile)
        {
            try {
                upkFile.Header = await repository.LoadUpkFile(Path.Combine(settings.PathToGame, upkFile.GameFilename));

                await Task.Run(() => upkFile.Header.ReadHeaderAsync(onLoadProgress));

                file.IsErrored = false;
            }
            catch (Exception ex) {
                file.IsErrored = true;

                messenger.Send(new ApplicationErrorMessage {
                    HeaderText = $"Error Loading UPK File: {upkFile.GameFilename}", Exception = ex
                });
            }
        }
Exemplo n.º 2
0
        private async void onFileEntityViewModelChanged(object sender, PropertyChangedEventArgs e)
        {
            FileViewEntity file = sender as FileViewEntity;

            if (file == null)
            {
                return;
            }

            switch (e.PropertyName)
            {
            case "IsSelected":
            {
                if (file.IsSelected)
                {
                    notesViewModel.SelectedFile = file;

                    viewModel.Files.Where(f => f != file).ForEach(f => f.IsSelected = false);

                    messenger.Send(new FileLoadingMessage());

                    DomainUpkFile upkFile = allFiles.First(f => f.Filename == file.Filename);

                    selectedFile = upkFile;

                    if (upkFile.Header == null)
                    {
                        await loadUpkFile(file, upkFile);

                        if (file.IsErrored)
                        {
                            return;
                        }
                    }

                    upkFile.LastAccess = DateTime.Now;

                    messenger.Send(new FileLoadedMessage {
                            FileViewEntity = file, File = upkFile
                        });
                }

                break;
            }
            }
        }
Exemplo n.º 3
0
        private async void onFileViewEntityChanged(object sender, PropertyChangedEventArgs args)
        {
            FileViewEntity file = sender as FileViewEntity;

            if (file == null)
            {
                return;
            }

            switch (args.PropertyName)
            {
            case "IsSelected": {
                if (file.IsSelected)
                {
                    viewModel.Mods.Where(f => f != file).ForEach(f => f.IsSelected = false);

                    messenger.Send(new FileLoadingMessage());

                    DomainUpkFile upkFile = allMods.Single(f => f.GameFilename == file.GameFilename);

                    if (upkFile.Header == null)
                    {
                        await loadUpkFile(file, upkFile);

                        if (file.IsErrored)
                        {
                            return;
                        }
                    }

                    upkFile.LastAccess = DateTime.Now;

                    messenger.Send(new FileLoadedMessage {
                            FileViewEntity = file, File = upkFile
                        });
                }

                break;
            }

            default: {
                break;
            }
            }
        }
Exemplo n.º 4
0
        private async Task exportFileObjects(List <DomainUpkFile> files)
        {
            LoadProgressMessage message = new LoadProgressMessage {
                Text = "Exporting...", Total = files.Count
            };

            int compressor = menuViewModel.IsCompressorClusterFit ? 0 : menuViewModel.IsCompressorRangeFit ? 1 : 2;

            int errorMetric = menuViewModel.IsErrorMetricPerceptual ? 0 : 1;

            DdsSaveConfig config = new DdsSaveConfig(FileFormat.Unknown, compressor, errorMetric, menuViewModel.IsWeightColorByAlpha, false);

            foreach (DomainUpkFile file in files)
            {
                FileViewEntity fileEntity = viewModel.Files.Single(fe => fe.Id == file.Id);

                string directory = Path.Combine(settings.ExportPath, Path.GetDirectoryName(file.GameFilename), Path.GetFileNameWithoutExtension(file.GameFilename));

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                DomainHeader header = file.Header;

                if (header == null)
                {
                    try {
                        header = await repository.LoadUpkFile(Path.Combine(settings.PathToGame, file.GameFilename));

                        await Task.Run(() => header.ReadHeaderAsync(null));
                    }
                    catch (Exception ex) {
                        messenger.Send(new ApplicationErrorMessage {
                            HeaderText = "Error Loading UPK File", ErrorMessage = $"Filename: {file.GameFilename}", Exception = ex
                        });

                        fileEntity.IsErrored = true;

                        continue;
                    }
                }

                message.Current++;

                foreach (DomainExportTableEntry export in header.ExportTable)
                {
                    if (export.DomainObject == null)
                    {
                        try {
                            await export.ParseDomainObject(header, false, false);
                        }
                        catch (Exception ex) {
                            messenger.Send(new ApplicationErrorMessage {
                                HeaderText = "Error Parsing Object", ErrorMessage = $"Filename: {header.Filename}\nExport Name: {export.NameTableIndex.Name}\nType: {export.TypeReferenceNameIndex.Name}", Exception = ex
                            });

                            fileEntity.IsErrored = true;

                            continue;
                        }
                    }

                    if (!export.DomainObject.IsExportable)
                    {
                        continue;
                    }

                    string filename = Path.Combine(directory, $"{export.NameTableIndex.Name}{export.DomainObject.FileExtension}");

                    message.StatusText = filename;

                    messenger.Send(message);

                    await export.DomainObject.SaveObject(filename, config);
                }

                file.Header = null;
            }

            message.IsComplete = true;
            message.StatusText = null;

            messenger.Send(message);
        }
Exemplo n.º 5
0
        private async Task scanUpkFiles(List <DomainUpkFile> upkFiles)
        {
            isScanInProgress = true;

            LoadProgressMessage message = new LoadProgressMessage {
                Text = "Scanning UPK Files", Current = 0, Total = upkFiles.Count
            };

            List <DomainUpkFile> saveCache = new List <DomainUpkFile>();

            foreach (DomainUpkFile file in upkFiles)
            {
                FileViewEntity fileEntity = viewModel.Files.SingleOrDefault(fe => fe.Filename == file.Filename) ?? mapper.Map <FileViewEntity>(file);

                message.Current++;
                message.StatusText = Path.Combine(settings.PathToGame, file.GameFilename);

                messenger.Send(message);

                DomainExportVersion bestVersion = file.GetCurrentExports() ?? new DomainExportVersion {
                    Versions = new List <DomainVersion>()
                };

                if (bestVersion.Versions.Contains(version))
                {
                    //
                    // This should never happen.  Toss an error to the ui to track it.
                    //
                    messenger.Send(new ApplicationErrorMessage {
                        HeaderText = "Odd Situation", ErrorMessage = $"Tried to scan a file, but the current version was already accounted for. {file.GameFilename} {version}/{locale}", OpenErrorWindow = true
                    });

                    continue;
                }

                if (bestVersion.Filesize == file.Filesize)
                {
                    bestVersion.Versions.Add(version);

                    if (fileEntity.ExportTypes == null || !fileEntity.ExportTypes.Any())
                    {
                        fileEntity.ExportTypes = new ObservableCollection <string>(bestVersion.Types.Select(t => t.Name));
                    }
                }
                else
                {
                    await scanUpkFile(fileEntity, file);

                    List <DomainExportType> exports = new List <DomainExportType>();

                    foreach (string type in file.Header.ExportTable.Select(e => e.TypeReferenceNameIndex.Name).Distinct().OrderBy(s => s))
                    {
                        exports.Add(new DomainExportType {
                            Name        = type,
                            ExportNames = file.Header.ExportTable.Where(e => e.TypeReferenceNameIndex.Name == type).Select(e => e.NameTableIndex.Name).Distinct().OrderBy(s => s).ToList()
                        });
                    }

                    file.Exports.Add(new DomainExportVersion {
                        Versions = new List <DomainVersion> {
                            version
                        }, Locale = locale, Filesize = file.Header.FileSize, Types = exports
                    });

                    fileEntity.FileSize    = file.Header.FileSize;
                    fileEntity.ExportTypes = new ObservableCollection <string>(exports.Select(e => e.Name));

                    file.Header = null;
                }

                string path = Path.GetDirectoryName(file.GameFilename);

                if (path != null && path.ToLowerInvariant().EndsWith("cookedpc"))
                {
                    if (!menuViewModel.IsOfflineMode)
                    {
                        saveCache.Add(file);
                    }

                    if (saveCache.Count == 50)
                    {
                        remoteRepository.SaveUpkFile(saveCache.ToList()).FireAndForget();

                        saveCache.Clear();
                    }
                }
            }

            if (saveCache.Any())
            {
                remoteRepository.SaveUpkFile(saveCache.ToList()).FireAndForget();
            }

            message.IsComplete = true;

            messenger.Send(message);

            isScanInProgress = false;
        }
Exemplo n.º 6
0
        private async Task scanUpkFiles(List <DomainUpkFile> upkFiles)
        {
            isScanInProgress = true;

            LoadProgressMessage message = new LoadProgressMessage {
                Text = "Scanning UPK Files", Current = 0, Total = upkFiles.Count
            };

            List <DomainUpkFile> saveCache = new List <DomainUpkFile>();

            foreach (DomainUpkFile file in upkFiles)
            {
                FileViewEntity fileEntity = viewModel.Files.SingleOrDefault(fe => fe.Filename == file.Filename) ?? mapper.Map <FileViewEntity>(file);

                message.Current++;
                message.StatusText = Path.Combine(settings.PathToGame, file.GameFilename);

                messenger.Send(message);

                await scanUpkFile(fileEntity, file);

                file.FileSize = file.Header.FileSize;

                List <DomainExportType> exports = new List <DomainExportType>();

                foreach (string type in file.Header.ExportTable.Select(e => e.TypeReferenceNameIndex.Name).Distinct().OrderBy(s => s))
                {
                    exports.Add(new DomainExportType {
                        Name        = type,
                        ExportNames = file.Header.ExportTable.Where(e => e.TypeReferenceNameIndex.Name == type).Select(e => e.NameTableIndex.Name).Distinct().OrderBy(s => s).ToList()
                    });
                }

                file.Exports.Where(e => e.Version == version).ToList().ForEach(e => file.Exports.Remove(e));

                file.Exports.Add(new DomainExportVersion {
                    Version = version, Types = exports
                });

                fileEntity.FileSize    = file.Header.FileSize;
                fileEntity.ExportTypes = new ObservableCollection <string>(exports.Select(e => e.Name));

                file.Header = null;

                string path = Path.GetDirectoryName(file.GameFilename);

                if (path != null && path.ToLowerInvariant().EndsWith("cookedpc"))
                {
                    if (!menuViewModel.IsOfflineMode)
                    {
                        saveCache.Add(file);
                    }

                    if (saveCache.Count == 50)
                    {
                        remoteRepository.SaveUpkFile(saveCache).FireAndForget();

                        saveCache.Clear();
                    }
                }
            }

            if (saveCache.Any())
            {
                remoteRepository.SaveUpkFile(saveCache).FireAndForget();
            }

            message.IsComplete = true;

            messenger.Send(message);

            isScanInProgress = false;
        }