public static List <ImportFile> GetImportList(string mapPath) { List <ImportFile> result = null; IntPtr hMpq; if (StormLib.SFileOpenArchive(mapPath, 0u, 0u, out hMpq)) { var impFile = DetectImpFile(hMpq); if (impFile != null) { result = ReadImportFile(hMpq, impFile); } } if (hMpq != IntPtr.Zero) { StormLib.SFileCloseArchive(hMpq); } return(result); }
public static void Export(string mapPath, List <ImportFile> fileList, string destPath) { IntPtr hMpq; if (StormLib.SFileOpenArchive(mapPath, 0u, 0u, out hMpq)) { for (int i = 0; i < fileList.Count; i++) { var file = fileList[i]; if (!string.IsNullOrEmpty(file.OrigPath)) { var fp = Path.Combine(destPath, file.FilePath); Directory.CreateDirectory(Path.GetDirectoryName(fp)); StormLib.SFileExtractFile(hMpq, file.OrigPath, fp, 0u); } } } if (hMpq != IntPtr.Zero) { StormLib.SFileCloseArchive(hMpq); } }
public static SaveResult SaveImportList(string mapPath, List <ImportFile> fileList) { var result = new SaveResult(); var saved = true; IntPtr hMpq; if (saved &= StormLib.SFileOpenArchive(mapPath, 0u, 0u, out hMpq)) { var hashtableSize = 32u; var fileCount = (uint)fileList.Count + hashtableSize; while (hashtableSize < fileCount) { hashtableSize *= 2; } StormLib.SFileSetMaxFileCount(hMpq, hashtableSize); var failedFiles = new List <string>(); for (int i = 0; (i < fileList.Count) && saved; i++) { var file = fileList[i]; if (file.Deleted) { StormLib.SFileRemoveFile(hMpq, file.OrigPath, 0u); } else if (file.Changed) { if (string.IsNullOrEmpty(file.DiskPath)) { StormLib.SFileRenameFile(hMpq, file.OrigPath, file.FilePath); } else { StormLib.SFileRemoveFile(hMpq, file.OrigPath, 0u); if (!StormLib.SFileAddFileEx(hMpq, file.DiskPath, file.FilePath, 0x80000200u, 0x2u, 0x2u)) { failedFiles.Add(file.DiskPath); file.Deleted = true; } } } } result.FailedFiles = failedFiles; var impFile = DetectImpFile(hMpq); if (saved &= (impFile != null)) { saved &= WriteImportFile(hMpq, impFile, fileList); } StormLib.SFileCompactArchive(hMpq, null, false); } if (saved &= (hMpq != IntPtr.Zero)) { saved &= StormLib.SFileCloseArchive(hMpq); } result.Saved = saved; return(result); }