Ejemplo n.º 1
0
    public async Task SaveUpkFile(DomainUpkFile File) {
      UpkFile file = await Task.Run(() => mapper.Map<UpkFile>(File));

      RestRequest request = new RestRequest("UpkFile", Method.PUT) { RequestFormat = DataFormat.Json };

      request.AddBody(file);

      IRestResponse<string> response = await client.ExecuteTaskAsync<string>(request);

      if (response.StatusCode != HttpStatusCode.OK) throw new Exception(response.StatusDescription);

      File.Id = response.Data;
    }
Ejemplo n.º 2
0
    private async Task scanUpkFile(FileViewEntity file, DomainUpkFile upkFile) {
      try {
        upkFile.Header = await repository.LoadUpkFile(Path.Combine(settings.PathToGame, upkFile.GameFilename));

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

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

        messenger.Send(new ApplicationErrorMessage { HeaderText = "Error Scanning UPK File.", ErrorMessage = $"Scanning {upkFile.GameFilename}", Exception = ex });
      }
    }
Ejemplo n.º 3
0
 private static int domainUpkfileComparison(DomainUpkFile left, DomainUpkFile right) {
   return String.Compare(left.Filename, right.Filename, StringComparison.CurrentCultureIgnoreCase);
 }
Ejemplo n.º 4
0
    private async Task rebuildExports() {
      Dictionary<ExportedObjectViewEntity, List<ExportedObjectViewEntity>> filesToMod = viewModel.ExportsTree?.Traverse(e => Path.HasExtension(e.Filename) && e.IsChecked)
                                                                                                              .GroupBy(e => e.Parent)
                                                                                                              .ToDictionary(g => g.Key, g => g.ToList());

      if (filesToMod == null || !filesToMod.Any()) return;

      LoadProgressMessage message = new LoadProgressMessage { Text = "Rebuilding...", Total = filesToMod.Count };

      foreach(KeyValuePair<ExportedObjectViewEntity, List<ExportedObjectViewEntity>> pair in filesToMod) {
        string gameFilename = $"{pair.Key.Filename.Replace(settings.ExportPath, null)}.upk";

        DomainUpkFile file = allFiles.SingleOrDefault(f => f.GameFilename.Equals(gameFilename));

        if (file == null) continue;

        DomainHeader header = await repository.LoadUpkFile(Path.Combine(settings.PathToGame, file.GameFilename));

        await header.ReadHeaderAsync(null);

        message.Current++;

        foreach(ExportedObjectViewEntity entity in pair.Value) {
          DomainExportTableEntry export = header.ExportTable.SingleOrDefault(ex => ex.NameTableIndex.Name.Equals(Path.GetFileNameWithoutExtension(entity.Filename), StringComparison.CurrentCultureIgnoreCase));

          if (export == null) continue;

          await export.ParseDomainObject(header, false, false);

          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);

          await export.DomainObject.SetObject(entity.Filename, header.NameTable, config);

          message.StatusText = entity.Filename;

          messenger.Send(message);
        }

        string directory = Path.Combine(settings.PathToGame, Path.GetDirectoryName(file.GameFilename), "mod");

        string filename = Path.Combine(directory, Path.GetFileName(file.GameFilename));

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

        await repository.SaveUpkFile(header, filename);

        DomainUpkFile upkFile = new DomainUpkFile { GameFilename = filename.Replace(settings.PathToGame, null), FileSize = new FileInfo(filename).Length };

        messenger.Send(new ModFileBuiltMessage { UpkFile = upkFile });
      }

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

      messenger.Send(message);
    }
Ejemplo n.º 5
0
    private void onFileLoaded(FileLoadedMessage message) {
      viewModel.File   = message.FileViewEntity;
      viewModel.Header = mapper.Map<HeaderViewEntity>(message.File.Header);

      upkfile = message.File;
    }
Ejemplo n.º 6
0
    private void onHeaderLoading(FileLoadingMessage message) {
      viewModel.File   = null;
      viewModel.Header = null;

      upkfile = null;
    }