public void GenerateWsModel() { try { var isAllVisible = _editableMeshNode.AreAllNodesVisible(); bool onlySaveVisible = false; if (isAllVisible == false) { if (MessageBox.Show("Only generate for visible nodes?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { onlySaveVisible = true; } } var modelFile = _kitbasherViewModel.MainFile as PackFile; var modelFilePath = _packFileService.GetFullPath(modelFile); var wsModelPath = Path.ChangeExtension(modelFilePath, ".wsmodel"); var existingWsModelFile = _packFileService.FindFile(wsModelPath, _packFileService.GetEditablePack()); var wsModelData = GenerateWsModel(modelFilePath, onlySaveVisible, out var wsModelGeneratedPerfectly); if (wsModelGeneratedPerfectly == false) { MessageBox.Show("Unable to correclty generate WS model, this file needs manual work before its can be used by the game!"); } SaveHelper.Save(_packFileService, wsModelPath, existingWsModelFile as PackFile, Encoding.UTF8.GetBytes(wsModelData)); } catch (Exception e) { _logger.Here().Error("Error generating ws model - " + e.ToString()); MessageBox.Show("Generation failed!"); } }
public static void Save(PackFileService packFileService, PackFile inputFile) { var selectedEditabelPackFile = packFileService.GetEditablePack(); var filePackFileConainer = packFileService.GetPackFileContainer(inputFile); if (selectedEditabelPackFile == null) { MessageBox.Show("No editable pack selected!"); return; } if (filePackFileConainer != selectedEditabelPackFile) { var filePath = packFileService.GetFullPath(inputFile, filePackFileConainer); packFileService.CopyFileFromOtherPackFile(filePackFileConainer, filePath, selectedEditabelPackFile); } }
public static PackFile Save(PackFileService packFileService, string filename, PackFile packFile, byte[] updatedData = null, bool promptSaveOverride = true) { filename = filename.ToLower(); var selectedEditabelPackFile = packFileService.GetEditablePack(); if (selectedEditabelPackFile == null) { MessageBox.Show("No editable pack selected!"); return(null); } var existingFile = packFileService.FindFile(filename, selectedEditabelPackFile); if (existingFile != null && promptSaveOverride) { var fullPath = packFileService.GetFullPath(existingFile as PackFile, selectedEditabelPackFile); if (MessageBox.Show($"Replace existing file?\n{fullPath} \nin packfile:{selectedEditabelPackFile.Name}", "", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { var extention = Path.GetExtension(fullPath); using (var browser = new SavePackFileWindow(packFileService)) { browser.ViewModel.Filter.SetExtentions(new List <string>() { extention }); if (browser.ShowDialog() == true) { var path = browser.FilePath; if (path.Contains(extention) == false) { path += extention; } filename = path; existingFile = null; } else { return(null); } } } } if (existingFile == null) { var directoryPath = Path.GetDirectoryName(filename); var justFileName = Path.GetFileName(filename); var data = updatedData; if (data == null) { data = packFile.DataSource.ReadData(); } var newPackFile = new PackFile(justFileName, new MemorySource(data)); packFileService.AddFileToPack(selectedEditabelPackFile, directoryPath, newPackFile); return(newPackFile); } else { if (updatedData == null) { throw new Exception("Trying to update an existing file, but no data is provided"); } packFileService.SaveFile(existingFile as PackFile, updatedData); return(existingFile as PackFile); } }