private void contextMenu_Opened(object sender, EventArgs e) { var selectedNode = modFileList.SelectedNode; if (selectedNode != null) { var fi = new FileInfo(selectedNode.FullPath); var ext = fi.Extension.TrimStart('.'); bool isbundle = Path.Combine(ActiveMod.FileDirectory, fi.ToString()).Contains(Path.Combine(ActiveMod.ModDirectory, new Bundle().TypeName)); bool israw = Path.Combine(ActiveMod.FileDirectory, fi.ToString()).Contains(Path.Combine(ActiveMod.FileDirectory, "Raw")); cookToolStripMenuItem.Enabled = (!Enum.GetNames(typeof(EImportable)).Contains(ext) && !isbundle && !israw); markAsModDlcFileToolStripMenuItem.Enabled = isbundle; importAsToolStripMenuItem.Enabled = Enum.GetNames(typeof(EImportable)).Contains(ext) && !isbundle && israw; importAsToolStripMenuItem.DropDown.Items.Clear(); var types = REDTypes.RawExtensionToRedImport(ext); foreach (var t in types) { importAsToolStripMenuItem.DropDown.Items.Add(t); } } pasteToolStripMenuItem.Enabled = File.Exists(Clipboard.GetText()); removeFileToolStripMenuItem.Enabled = modFileList.SelectedNode != null; renameToolStripMenuItem.Enabled = modFileList.SelectedNode != null; copyRelativePathToolStripMenuItem.Enabled = modFileList.SelectedNode != null; copyToolStripMenuItem.Enabled = modFileList.SelectedNode != null; showFileInExplorerToolStripMenuItem.Enabled = modFileList.SelectedNode != null; }
/// <summary> /// Exports an existing file in the ModProject (w2mesh, redcloth) to the modProject /// </summary> /// <param name="fullpath"></param> /// <returns></returns> public static async Task ExportFileToMod(string fullpath) { string workDir = Path.GetFullPath($"{MainController.WorkDir}_export"); if (!Directory.Exists(workDir)) { Directory.CreateDirectory(workDir); } Directory.Delete(workDir, true); // check if physical file exists if (!File.Exists(fullpath)) { Logger.LogString($"File to export does not exist {fullpath}.", Logtype.Error); return; } // check if the extension matches an exportable format string importedExtension = Path.GetExtension(fullpath).TrimStart('.'); EImportable exportedExtension; try { exportedExtension = REDTypes.ExportExtensionToRawExtension((EExportable)Enum.Parse(typeof(EExportable), importedExtension)); } catch (Exception ex) { Logger.LogString($"Not an exportable filetype: {importedExtension}.", Logtype.Error); return; } // get relative path (string relativePath, bool isDLC, EProjectFolders projectFolder) = fullpath.GetModRelativePath(ActiveMod.FileDirectory); var exportpath = isDLC ? Path.Combine(ActiveMod.RawDirectory, "DLC", relativePath) : Path.Combine(ActiveMod.RawDirectory, "Mod", relativePath); exportpath = Path.ChangeExtension(exportpath, exportedExtension.ToString()); // add all imports to //string workDir = ""; // add to mod //string workDir = MainController.Get().Configuration.DepotPath; // r4depot AddAllImports(fullpath, true, true, workDir); // copy the w2mesh and all imports to the depot var depotInfo = new FileInfo(Path.Combine(workDir, relativePath)); var uncookedInfo = new FileInfo(fullpath); uncookedInfo.CopyToAndCreate(depotInfo.FullName, true); // export with wcc_lite if (!string.IsNullOrEmpty(relativePath) && !string.IsNullOrEmpty(exportpath)) { // uncook the folder var export = new Wcc_lite.export() { File = relativePath, Out = exportpath, Depot = workDir }; await Task.Run(() => MainController.Get().WccHelper.RunCommand(export)); if (File.Exists(exportpath)) { Logger.LogString($"Successfully exported {relativePath}.", Logtype.Success); } else { Logger.LogString($"Did not export {relativePath}.", Logtype.Error); } } }