public BodyModelSumPuppet(string pName, SevenZipArchiver pArchiver) { _Archiver = pArchiver; PuppetName = pName?.Trim(); _RootPath = $"data/puppets/{PuppetName.ToLower()}/"; _RootPathLength = _RootPath.Length; }
public AddonPackageSource(string pSourcePath, string pArchivedPath = null) { if (string.IsNullOrEmpty(pSourcePath = pSourcePath.Trim())) { throw new Exception("Not a valid path specification"); } pSourcePath = Path.GetFullPath(pSourcePath); ArchivedPath = pArchivedPath; if (Directory.Exists(pSourcePath)) { SourceType = AddonPackageSourceType.Folder; SourcePath = pSourcePath; return; } SevenZipArchiver archiver = new SevenZipArchiver(pSourcePath); List <ArchiveFileInfo> files; if (archiver.ArchivedFileList(out files) < 0) { string errorText = string.IsNullOrEmpty(archiver.LastErrorText) ? "Not a valid archive" : archiver.LastErrorText; throw new Exception(errorText); } Archiver = archiver; SourceType = AddonPackageSourceType.Archiver; SourcePath = pSourcePath; }
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------ public bool CreateAddonFile(string newAddonFilePath, bool pNoMeatFiles, out string pErrorText) { pErrorText = null; string addonFolder = AddonFolder; if (pNoMeatFiles) { // No meaty files Regex meatyFileMaskRegex = AddonContents.GetMeatyFileMaskRegex(); string tempAddonFolder = GetTempAddonFolder(); if (!DirectoryCopy(AddonFolder, tempAddonFolder, true, meatyFileMaskRegex, out pErrorText)) { return(false); } addonFolder = tempAddonFolder; } SevenZipArchiver archiver = new SevenZipArchiver(newAddonFilePath); if (!archiver.ArchiveFolder(addonFolder)) { pErrorText = archiver.LastErrorText; return(false); } return(true); }
private bool CheckFormat(SevenZipArchiver pArchiver, List <ArchiveFileInfo> pArchiveEntryList, out bool pHasMeshes, out bool pHasData, out List <string> pDemoMovies, out List <string> pStockAssets, out AddonSignatureFile pAddonSignature) { List <string> fileNames = new List <string>(); pHasMeshes = false; List <string> movies = new List <string>(); List <string> stocks = new List <string>(); pHasData = false; pAddonSignature = null; foreach (ArchiveFileInfo entry in pArchiveEntryList) { string lwrName; fileNames.Add(lwrName = entry.FileName?.Trim().ToLower()); if (!pHasData) { if (lwrName?.StartsWith(@"data\") ?? false) { pHasData = true; } } if (lwrName?.StartsWith(@"movies\") ?? false) { string movieName = GetSubitemName(entry.FileName, "movies"); if (!string.IsNullOrEmpty(movieName) && !movies.Contains(movieName)) { movies.Add(movieName); } } if (lwrName?.StartsWith(@"stock\") ?? false) { string stockName = GetSubitemName(entry.FileName, "stock"); if (!string.IsNullOrEmpty(stockName) && !stocks.Contains(stockName)) { stocks.Add(stockName); } } } pDemoMovies = movies.Count > 0 ? movies : null; pStockAssets = stocks.Count > 0 ? stocks : null; pHasMeshes = fileNames.Contains("meshdata.data") && fileNames.Contains("meshdata.index"); bool formatOk = fileNames.Contains(".addon") && fileNames.Contains("assetdata.jar"); byte[] addonContent = pArchiver.ExtractArchivedFileToByte(".addon"); if (addonContent != null) { pAddonSignature = AddonSignatureFile.Load(addonContent); } return(formatOk && (pAddonSignature != null)); }
public PropModelSumProp(string pName, SevenZipArchiver pArchiver) { _archiver = pArchiver; PropName = pName?.Trim(); // ************ CAVEAT ************ _rootPath = $"data/props/{PropName.ToLower()}/"; _rootPathLength = _rootPath.Length; }
// ------------------------------------------------------------------------------------------------------------------------- private List <string> CreateAssetList(string pManifestFilePath, string pTemporaryFolder, string pManifestContentMirror, out string pErrorText) { pErrorText = null; string tempAssetZipFile = Path.Combine(pTemporaryFolder, "assetData.zip"); SevenZipArchiver archiver = new SevenZipArchiver(tempAssetZipFile); List <string> fileList = null; try { File.Copy(pManifestFilePath, tempAssetZipFile, true); // Extracts contents of Manifest file to TemporaryFolder if (archiver.ArchivedFilesExtract(pManifestContentMirror, null) < 0) { pErrorText = archiver.LastErrorText; return(null); } // Create List of files List <ArchiveFileInfo> archiveFilesInfo; archiver.ArchivedFileList(out archiveFilesInfo); if (archiveFilesInfo != null) { fileList = new List <string>(); foreach (ArchiveFileInfo item in archiveFilesInfo) { string fileName = item.FileName; if (fileName.StartsWith("Data", StringComparison.InvariantCultureIgnoreCase)) { fileList.Add(fileName); } } } } catch (Exception exception) { pErrorText = exception.Message; return(null); } finally { if (File.Exists(tempAssetZipFile)) { File.Delete(tempAssetZipFile); } } fileList?.Sort(); return(fileList); }
public AddonPackageSource(SevenZipArchiver pArchiver, string pArchivedPath = null) { if (pArchiver == null) { throw new Exception("Not a valid Archiver specification"); } Archiver = pArchiver; SourceType = AddonPackageSourceType.Archiver; if (pArchiver.Source == SevenZipArchiverSource.File) { SourcePath = pArchiver.ArchiveName; } ArchivedPath = pArchivedPath; }
private bool CheckEntity(ProcessingFlags pProcessingFlags, out string pReport) { // bool reportOnlyIssues = pProcessingFlags.HasFlag(ProcessingFlags.JustReportIssues); // bool showAddonContents = pProcessingFlags.HasFlag(ProcessingFlags.ShowAddonContents); pReport = null; SevenZipArchiver archiver = new SevenZipArchiver(AbsolutePath); List <ArchiveFileInfo> archiveEntryList; List <string> fileList = GetFileList(archiver, out archiveEntryList); if ((fileList?.Count ?? -1) <= 0) { return(false); } return(CheckFiles(pProcessingFlags, archiver, archiveEntryList, fileList, out pReport)); }
public bool AppendItem(SevenZipArchiver pArchiver, string pFile, out string pErrorText) { string directory = Path.GetDirectoryName(pFile); string folder = pFile.ToLower().Replace(CuttingRoomAssetsPathPrefix, "").Replace(ObjectDatFilenameSuffix, ""); string fileText = null; string name = null; string assetInfoFile = Path.Combine(directory, CuttingRoomAssetsSummary.AssetInfoFilename); if (pArchiver.FileExists(assetInfoFile)) { fileText = pArchiver.ExtractArchivedFileToString(assetInfoFile); } else { name = GetAssetName(directory); } return(DoAppendItem(folder, fileText, name, out pErrorText)); }
/// <summary> /// Recreate Manifest file from mirror folder /// </summary> /// <param name="pErrorText">Text of error, if any</param> /// <returns>Result of operation</returns> public bool RefreshManifestFromMirror(out string pErrorText) { if (!CheckPaths(out pErrorText)) { return(false); } string tempAssetZipFile = Path.Combine(TemporaryFolder, "assetData.zip"); SevenZipArchiver archiver = new SevenZipArchiver(tempAssetZipFile); try { if (!archiver.ArchiveFolder(ManifestContentMirrorPath)) { pErrorText = archiver.LastErrorText; return(false); } File.Copy(tempAssetZipFile, ManifestFilePath, true); } catch (Exception exception) { pErrorText = exception.Message; return(false); } finally { if (File.Exists(tempAssetZipFile)) { File.Delete(tempAssetZipFile); } } // Recreate Asset List AssetList = RecreateAssetList(); return(true); }
private List <string> GetFileList(SevenZipArchiver pArchiver, out List <ArchiveFileInfo> pEntryList) { pArchiver.ArchivedFileList(out pEntryList); if ((pEntryList?.Count ?? -1) <= 0) { return(null); } List <string> fileList = new List <string>(); foreach (ArchiveFileInfo entry in pEntryList) { string entryLower = entry.FileName.ToLower(); if (!entry.IsDirectory && (entryLower.EndsWith(".addon") || entryLower.EndsWith(".skp"))) { fileList.Add(entry.FileName); } } fileList.Sort(); return(fileList); }
private CuttingRoomAssetCollection CreateAssetsSummary(SevenZipArchiver pArchiver, out string pErrorText) { pErrorText = null; CuttingRoomAssetCollection assets = new CuttingRoomAssetCollection(); List <ArchiveFileInfo> files; pArchiver.ArchivedFileList(out files); foreach (ArchiveFileInfo file in files) { string fileNameLower = file.FileName.ToLower(); if (fileNameLower.StartsWith(CuttingRoomAssetsPath) && fileNameLower.EndsWith(ObjectDatFilename)) { if (!assets.AppendItem(pArchiver, file.FileName, out pErrorText)) { return(null); } } } return(assets.HasData ? assets : null); }
/// <summary> /// Checks files inside the archive /// </summary> /// <param name="pProcessingFlags">Processing flags</param> /// <param name="pArchiver">Archiver used to manage the archive contents</param> /// <param name="pArchiveEntryList">Full information about files in archive</param> /// <param name="pFileList">List of files inside the archive</param> /// <param name="pReport">Output text</param> /// <returns>Result of check</returns> private bool CheckFiles(ProcessingFlags pProcessingFlags, SevenZipArchiver pArchiver, List <ArchiveFileInfo> pArchiveEntryList, List <string> pFileList, out string pReport) { // bool reportOnlyIssues = pProcessingFlags.HasFlag(ProcessingFlags.JustReportIssues); // bool showAddonContents = pProcessingFlags.HasFlag(ProcessingFlags.ShowAddonContents); string rootTempPath = Utils.GetTempDirectory(); pArchiver.ArchivedFilesExtract(rootTempPath, pFileList); string currentPath = Utils.GetExecutableDirectory(); Directory.SetCurrentDirectory(rootTempPath); pReport = null; try { foreach (string fileName in pFileList) { string extension = Path.GetExtension(fileName)?.Trim().ToLower(); bool isAddonFile = false; if (extension == ".addon") { if (fileName.ToLower() == ".addon") { string rootFolder; if (!InsideArchive && pProcessingFlags.HasFlag(ProcessingFlags.CorrectDisguisedFiles) && IsValidAddon(pArchiveEntryList, false, out rootFolder)) { string errorText; string newAddonFile = AddonPersistenceUtils.CorrectAddonFile(pArchiver, pProcessingFlags.HasFlag(ProcessingFlags.CorrectDisguisedFilesDeleteSource), null, out errorText); if (newAddonFile == null) { pReport = $" {ErrorTokenString} Possibly an Addon file disguised as an archive. Failed to restore: {errorText}"; return(false); } pReport = $" Addon file disguised as an archive. Restored: {Path.GetFileName(newAddonFile)}"; return(true); } else { pReport = $" {ErrorTokenString} Possibly an Addon file disguised as an archive"; return(false); } } if (fileName.ToLower().EndsWith(@"\.addon")) { string rootFolder; if (!InsideArchive && pProcessingFlags.HasFlag(ProcessingFlags.CorrectDisguisedFiles) && IsValidAddon(pArchiveEntryList, true, out rootFolder)) { string errorText; string newAddonFile = AddonPersistenceUtils.CorrectAddonFile(pArchiver, pProcessingFlags.HasFlag(ProcessingFlags.CorrectDisguisedFilesDeleteSource), rootFolder, out errorText); if (newAddonFile == null) { pReport = $" {ErrorTokenString} Possibly an Addon file disguised as an archive. Failed to restore: {errorText}"; return(false); } pReport = $" Addon file disguised as an archive. Restored: {Path.GetFileName(newAddonFile)}"; return(true); } else { pReport = $" {ErrorTokenString} Possibly an Addon file disguised as an archive, with a root directory"; return(false); } } isAddonFile = true; } string archivedPath = $"{AbsolutePath}#{fileName}"; IDiskEntity diskEntity = isAddonFile ? new DiskEntityAddon(fileName, archivedPath, ReportWriter) : (IDiskEntity) new DiskEntitySketchup(fileName, archivedPath, ReportWriter); diskEntity.CheckEntity(pProcessingFlags); File.Delete(fileName); } } catch { } finally { Directory.SetCurrentDirectory(currentPath); } return(true); }
public PropModelSumProps(SevenZipArchiver pArchiver) { Archiver = pArchiver; }
public BodyModelSumPuppets(SevenZipArchiver pArchiver) { Archiver = pArchiver; }
public BodyModelSumBodyPart(SevenZipArchiver pArchiver, string pPuppetName) { _Archiver = pArchiver; PuppetName = pPuppetName; }
private bool CheckEntity(ProcessingFlags pProcessingFlags, out string pReport) { bool reportOnlyIssues = pProcessingFlags.HasFlag(ProcessingFlags.JustReportIssues); bool showAddonContents = pProcessingFlags.HasFlag(ProcessingFlags.ShowAddonContents); bool appendToPackageSet = pProcessingFlags.HasFlag(ProcessingFlags.AppendToAddonPackageSet); List <ArchiveFileInfo> entryList; SevenZipArchiver archiver = new SevenZipArchiver(AbsolutePath); archiver.ArchivedFileList(out entryList); if ((entryList?.Count ?? -1) <= 0) { pReport = $"{ErrorTokenString} Invalid file or format"; if (showAddonContents) { pReport += "\n"; } return(false); } List <string> demoMovies, stockAssets; bool hasMeshes, hasData; AddonSignatureFile addonSignature; bool formatOk = CheckFormat(archiver, entryList, out hasMeshes, out hasData, out demoMovies, out stockAssets, out addonSignature); if (!formatOk) { pReport = $"{ErrorTokenString} Invalid/obsolete addon format"; if (showAddonContents) { pReport += "\n"; } return(false); } // Addon good format pReport = null; if (reportOnlyIssues) { return(true); } if (!showAddonContents) { pReport = (hasMeshes ? "OK" : "OK, no meshes"); if (demoMovies != null) { pReport += " (incl. Movies)"; } if (stockAssets != null) { pReport += " (incl. Stock assets)"; } string freeText = addonSignature.Free ? "" : " NOT FREE!"; pReport += $" [{addonSignature.Publisher}{freeText}]"; if (!appendToPackageSet) { return(true); } } string tempPath = Utils.GetTempDirectory(); AddonPackage package = new AddonPackage(archiver, pProcessingFlags, tempPath, ArchivedPath); if (showAddonContents) { pReport = package?.ToString(); } if (appendToPackageSet && (AddonPackageSet != null) && (package != null)) { if (package.HasIssues) { pReport += " >>> Not inserted/updated into Catalogue (has problems!)"; } else { if (AddonPackageSet.Append(package, pProcessingFlags.HasFlag(ProcessingFlags.AppendToAddonPackageSetForceRefresh))) { pReport += " >>> Inserted/updated into Catalogue"; } } } return(true); }
// --------------------------------------------------------------------------------------------------------- public bool PopulateSummary(out string pErrorText, AddonPackageSource pSource = null, string pTempFolderPath = null, List <BodyModelItem> pBodyModels = null) { pErrorText = null; if (_initialized) { return(true); } if (!PopulateSummaryPreChecks(ref pSource, ref pTempFolderPath, ref pBodyModels, out pErrorText)) { return(false); } bool isOk = true; string assetDataFile = null; bool deleteTempAssetDataFile = false; try { if (pSource.SourceType == AddonPackageSourceType.Folder) { assetDataFile = Path.Combine(pSource.SourcePath, AddonPackage.AssetDataFilename); } else { assetDataFile = Path.Combine(pTempFolderPath, AddonPackage.AssetDataFilename); pSource.Archiver.ArchivedFilesExtract(pTempFolderPath, new List <string>() { AddonPackage.AssetDataFilename }); deleteTempAssetDataFile = true; } List <string> puppetTextureList = GetPuppetTextures(pSource); SevenZipArchiver mftArchiver = new SevenZipArchiver(assetDataFile); foreach (BodyModelItem item in pBodyModels) { if (Puppets == null) { Puppets = new BodyModelSumPuppets(mftArchiver); } if (!Puppets.AppendBodyModelItem(item, puppetTextureList, LoadAnimations, out pErrorText)) { isOk = false; break; } } } catch (Exception exception) { pErrorText = $"BodyModelsSummary.PopulateSummary() EXCEPTION: {exception.Message}"; isOk = false; } finally { if (deleteTempAssetDataFile) { File.Delete(assetDataFile); } } _initialized = isOk; return(isOk); }