public static void InitializePackageManagement(this frmMain form) { string _namespace = MethodBase.GetCurrentMethod().ToLogFormatFullName(); string[] directories = null; try { directories = Directory.GetDirectories(PMFileSystem.PackMan_ManDir); } catch (Exception ex) { Helper.ShowMessageBox(MessageBoxStrings.PackageManagement.INIT_GLOBAL_GET_DIRS_ERROR, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); Logger.WriteErrorLog(LoggerMessages.PackageManagement.GLOBAL_DIR_ERROR + PMFileSystem.PackMan_ManDir + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error); return; } if (directories == null || directories.Length == 0) { return; } LogDataList log = new LogDataList(); foreach (string directory in directories) { LogDataList outLog = null; try { GlobalPackages.AddSafely(new InstalledPackage(directory, _namespace, out outLog)); } catch (Exception ex) { log.WriteWarningLog(LoggerMessages.PackageManagement.InstalledPackage.Error.ErrorTryLoad(directory), _namespace, ex); if (ex is InvalidInstalledPackageFile castedEx) { log.WriteErrorLog(castedEx.Message, _namespace, castedEx.InnerException); } else { log.WriteErrorLog(ex.Message, _namespace, ex); } } log.AppendLogs(outLog); } if (log.HasErrorsOrWarnings()) { Helper.ShowMessageBox(MessageBoxStrings.PackageManagement.INIT_ERROR_WARNS_FOUND, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Logger.WriteInformationLog(LoggerMessages.PackageManagement.INIT_GLOBAL_DIR + PMFileSystem.PackMan_ManDir + ".", _namespace); } }
TreeNode AddFiles(string[] filePaths, string _namespace) { if (filePaths == null) { return(null); } TreeNode retVal = null; LogDataList log = new LogDataList(); foreach (string path in filePaths) { try { retVal = AddFile(tViewAssets.SelectedNode, path, _namespace); } catch (Exception ex) { log.WriteErrorLog(frmPackageAssetsMessages.Error.UnableAddFileSingle(path), _namespace, ex); } } if (log != null && log.HasErrorsOrWarnings()) { Helper.ShowMessageBox(MessageBoxStrings.General.HAS_ERRORS_WARNINGS, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning); frmLogger loggerForm = new frmLogger(_logList: log); loggerForm.StartPosition = FormStartPosition.CenterParent; loggerForm.ShowDialog(); } return(retVal); }
public static void RetrieveSubCharacterImages(string path, string rootPath, string _namespace, bool trimRootPath, out LogDataList log, ref List <RMCharImageGroup> collection, RMCharImageFile.ImageTypes imageType, RMCharImageCollection parent) { log = new LogDataList(); log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedAutoData(parent.Parent.Name, path, RMCollectionType.Characters), _namespace); string[] files = null; try { files = Directory.GetFiles(path, "*" + RMPConstants.GenFileNamePrefixANDSuffix.PNG); } catch (Exception ex) { log.WriteErrorLog(LoggerMessages.RMPackage.Error.RetrieveAutoError(path, parent.Parent.Name, RMCollectionType.Characters), _namespace, ex); return; } if (files == null || files.Length == 0) { return; } for (int i = 0; i < files.Length; ++i) { string realFileName = Path.GetFileNameWithoutExtension(files[i]); if (string.IsNullOrWhiteSpace(realFileName)) { continue; } string nonLoweredPath = files[i]; files[i] = files[i].ToLower(); string fileName = realFileName.ToLower(); string rootFileName; bool atlas = IsAnAtlasPartFile(realFileName, out rootFileName); RMCharImageGroup parentNode; parentNode = collection.FindByInternalName((atlas) ? rootFileName.ToLower() : fileName); if (parentNode == null) { parentNode = new RMCharImageGroup(parent); parentNode.internalName = (atlas) ? rootFileName.ToLower() : fileName; parentNode.Name = (atlas) ? rootFileName : realFileName; collection.Add(parentNode); } RMCharImageFile newFile = new RMCharImageFile(parentNode); newFile.FileName = realFileName; newFile.ImageType = imageType; if (trimRootPath) { newFile.Path = Helper.GetRelativePath(nonLoweredPath, rootPath); } else { newFile.Path = nonLoweredPath; } parentNode.Files.Add(newFile); log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedFile(parent.Parent.Name, nonLoweredPath, RMCollectionType.Characters), _namespace); } }
internal static RMSingleFileCollection RetrieveSingleFileCollection(string path, string rootPath, string _namespace, bool trimRootPath, out LogDataList log, RMSingleFileCollection.CollectionType typeOfCollection, RMPackage package) { log = new LogDataList(); log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedAutoData(package.Name, path, typeOfCollection.ToRMCollectionType()), _namespace); RMSingleFileCollection newCollection = typeOfCollection.ToNewClassInstance(package); string fileExtension = typeOfCollection.ToFileExtension(); if (newCollection == null) { return(null); } string[] files = null; try { files = Directory.GetFiles(path, "*." + fileExtension); } catch (Exception ex) { log.WriteErrorLog(LoggerMessages.RMPackage.Error.RetrieveAutoError(path, package.Name, typeOfCollection.ToRMCollectionType()), _namespace, ex); return(null); } if (files == null || files.Length == 0) { return(null); } for (int i = 0; i < files.Length; i++) { string originalFileName = Path.GetFileNameWithoutExtension(files[i]); if (string.IsNullOrWhiteSpace(originalFileName)) { continue; } RMSingleFile newDataFile = new RMSingleFile(newCollection); if (trimRootPath) { newDataFile.Path = Helper.GetRelativePath(files[i], rootPath); } else { newDataFile.Path = files[i]; } newDataFile.FileName = originalFileName; newCollection.Files.Add(newDataFile); log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedFile(package.Name, files[i], typeOfCollection.ToRMCollectionType()), _namespace); } if (newCollection.Files.Count == 0) { return(null); } return(newCollection); }
public static LogDataList MakeLogSet(this IEnumerable <BoolAndRMFile> listOfBoolAndRM, string prefixStr, string _namespace, string rootDir = null) { if (listOfBoolAndRM == null || listOfBoolAndRM.Count() == 0) { return(null); } LogDataList log = new LogDataList(); string resultingText = (string.IsNullOrWhiteSpace(prefixStr)) ? "" : prefixStr; resultingText += LoggerMessages.Extension.MISS_FILE; if (!string.IsNullOrWhiteSpace(rootDir)) { resultingText += rootDir + "\\"; } foreach (BoolAndRMFile boolAndRMFile in listOfBoolAndRM) { if (!boolAndRMFile.Boolean) { log.WriteErrorLog(resultingText + boolAndRMFile.PackFile.Path + LoggerMessages.Extension.MISS_FILE_1, _namespace, null); } } return(log); }
public static RMMovieCollection RetrieveMovieCollection(string path, string rootPath, string _namespace, bool trimRootPath, out LogDataList log, RMPackage parent) { log = new LogDataList(); RMMovieCollection newCollection = new RMMovieCollection(parent); log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedAutoData(parent.Name, path, RMCollectionType.Movies), _namespace); string[] files = null; try { files = Directory.GetFiles(path); } catch (Exception ex) { log.WriteErrorLog(LoggerMessages.RMPackage.Error.RetrieveAutoError(path, parent.Name, RMCollectionType.Movies), _namespace, ex); return(null); } if (files == null || files.Length == 0) { return(null); } for (int i = 0; i < files.Length; ++i) { string originalFileName = Path.GetFileNameWithoutExtension(files[i]); string nonLoweredPath = files[i]; files[i] = files[i].ToLower(); string fileName = originalFileName.ToLower(); string fileExtension = Path.GetExtension(files[i]); if (fileExtension.Length < RMPConstants.MovieFileType.MP4.Length + 1) { continue; } fileExtension = fileExtension.Substring(1); RMMovieFile.FileType typeOfFile = RMMovieFile.FileType.none; typeOfFile = typeOfFile.ParseString(fileExtension); if (typeOfFile == RMMovieFile.FileType.none || string.IsNullOrWhiteSpace(originalFileName)) { continue; } RMMovieGroup rmv = newCollection.Groups.FindByInternalName(fileName); if (rmv == null) { rmv = new RMMovieGroup(newCollection); rmv.Name = originalFileName; rmv.internalName = fileName; newCollection.Groups.Add(rmv); } RMMovieFile rmf = new RMMovieFile(rmv); if (trimRootPath) { rmf.Path = Helper.GetRelativePath(nonLoweredPath, rootPath); } else { rmf.Path = nonLoweredPath; } rmf.TypeOfFile = typeOfFile; rmv.Files.Add(rmf); log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedFile(parent.Name, nonLoweredPath, RMCollectionType.Movies), _namespace); } if (newCollection.Groups.Count == 0) { return(null); } return(newCollection); }
public static void MakeInstalledPackageFileForDefPackage(string XmlPath, string _namespace, out LogDataList log, string rootDirectory = null, bool ignoreClash = false) { log = new LogDataList(); log.WriteInformationLog(MakeInstalledPackagesMessages.Info.CreateInstalledPack(XmlPath, rootDirectory), _namespace); LogDataList outLog = null; RMPackage newPack = null; Exception exResult; try { newPack = new RMPackage(XmlPath, _namespace, out outLog, rootDirectory); } catch (Exception ex) { log.AppendLogs(outLog); Logger.WriteErrorLog(MakeInstalledPackagesMessages.Error.InvalidXML(XmlPath, rootDirectory), _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } log.AppendLogs(outLog); string origDir = newPack.XMLDirectory; InstalledPackage installedPackage = GlobalPackages.FindByUID(newPack.UniqueID); string newPackDir = PMFileSystem.PackMan_ManDir + "\\" + newPack.UniqueIDInMD5; if (installedPackage != null) { if (ignoreClash) { Logger.WriteWarningLog(MakeInstalledPackagesMessages.Warning.InstalledPackExistsExit(newPack.Name), _namespace, null); return; } else { log.WriteWarningLog(MakeInstalledPackagesMessages.Warning.InstalledPackExistsReplace(newPack.Name), _namespace); if (Helper.DeleteFolderSafely(newPackDir, _namespace, out exResult, new DeleteFolderLogMessages(deleteFailed: MakeInstalledPackagesMessages.Error.UnableToDeleteExistingFolder)) == DeleteFolderResult.UserCancelled) { throw exResult; } } } string tempPackDir = PMFileSystem.PackMan_TempDir + "\\" + newPack.UniqueIDInMD5; if (Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG) == DeleteFolderResult.UserCancelled) { throw exResult; } if (Helper.CreateFolderSafely(newPackDir, _namespace, out exResult, new CreateFolderLogMessages(createFailed: MakeInstalledPackagesMessages.Error.UnableCreateRootDir)) == CreateFolderResult.UserCancelled) { throw exResult; } if (Helper.CreateFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_CREATE_TEMP_DIR_ARG) == CreateFolderResult.UserCancelled) { throw exResult; } string backupXMLInstallerPath = tempPackDir + "\\" + Vars.INSTALL_FILE_DEFAULT_FILENAME; makeInstPackageAnon onErrorBackup = delegate() { if (Helper.ShowMessageBox(MessageBoxStrings.PackageManagement.FailedMakeInstallPackageArch(newPack.Name), MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { return(true); } Logger.WriteErrorLog(MakeInstalledPackagesMessages.Error.UserRequiredOnFailedBackUpNo(newPack.Name), _namespace, null, BasicDebugLogger.DebugErrorType.Error); Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG); Helper.DeleteFolderSafely(newPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_UNUSED_DIR_ARG); return(false); }; string rootPathOfFiles; if (rootDirectory == null) { rootPathOfFiles = newPack.XMLDirectory; } else { rootPathOfFiles = rootDirectory; } PackageUtil.ExplicitCopyAssetsAndLicFileTo(newPack, rootPathOfFiles, tempPackDir, _namespace); try { newPack.SaveToFile(backupXMLInstallerPath, _namespace, RMPackage.SaveToFileMode.ImplicitAssetInfo, logMessage: new WriteAllTextLogMessages(writeFailed: MakeInstalledPackagesMessages.Error.UnableCreateInstXML, logGroup: log)); } catch { if (onErrorBackup()) { goto onerrorContinue; } throw; } string archDest = newPackDir + "\\" + Vars.INSTALLED_ARCH_FILENAME; try { ArchiveManagement.CreateNewZip(tempPackDir, archDest, _namespace); } catch (Exception ex) { log.WriteWarningLog(MakeInstalledPackagesMessages.Error.UnableMakeBackup(newPack.Name, tempPackDir, archDest), _namespace, ex); if (onErrorBackup()) { goto onerrorContinue; } throw; } onerrorContinue: //newPack.Installed = true; //newPack.SetInstalledPropertyAll(RMPackObject.InstallStatus.Installed); if (newPack.License != null && newPack.License.LicenseSource == RMPackLic.Source.File && RMPackLic.IsAValidLicenseSourceFile(newPack.License.Data, origDir)) { string licSourcePath = origDir + "\\" + newPack.License.Data; string fileName = Path.GetFileName(licSourcePath); string destPath = newPackDir + "\\" + fileName; CopyFileResult copyRes = Helper.CopyFileSafely(licSourcePath, destPath, true, _namespace, out exResult, new CopyFileLogMessages(copyFileFailed: MakeInstalledPackagesMessages.Error.UnableCopyLicenseFile)); if (copyRes == CopyFileResult.UserCancelled || copyRes == CopyFileResult.SourceFileNotFound) { Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG); Helper.DeleteFolderSafely(newPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_UNUSED_DIR_ARG); throw exResult; } newPack.License.Data = fileName; } string installedXMLDest = newPackDir + "\\" + Vars.INSTALLED_XML_FILENAME; newPack.Implicit = false; try { newPack.SaveToFile(installedXMLDest, _namespace, RMPackage.SaveToFileMode.ExplicitAssetInfo, logMessage: new WriteAllTextLogMessages(writeFailed: MakeInstalledPackagesMessages.Error.UnableMakeMainXML)); } catch { Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG); Helper.DeleteFolderSafely(newPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_UNUSED_DIR_ARG); throw; } try { GlobalPackages.AddSafely(new InstalledPackage(newPackDir, _namespace, out outLog)); } catch (Exception ex) { log.WriteWarningLog(LoggerMessages.PackageManagement.InstalledPackage.Error.ErrorTryLoad(newPackDir), _namespace, ex); if (ex is InvalidInstalledPackageFile castedEx) { log.WriteErrorLog(castedEx.Message, _namespace, castedEx.InnerException); } else { log.WriteErrorLog(ex.Message, _namespace, ex); } } log.AppendLogs(outLog); try { NewProject.CopyPackageInstallInfo(tempPackDir, _namespace, out outLog); } catch (Exception ex) { log.WriteWarningLog(MakeInstalledPackagesMessages.Warning.UnableCopyNewProj(newPack.Name, newPackDir), _namespace, ex); } log.AppendLogs(outLog); Helper.DeleteFolderSafely(tempPackDir, _namespace, out exResult, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG); log.WriteInformationLog(MakeInstalledPackagesMessages.Info.SUCCESS_CREATE + newPack.Name + ".", _namespace); }
static void RetrieveGeneratorPartOnGender(string path, string rootPath, string _namespace, bool trimRootPath, out LogDataList log, ref List <RMGenPart> partsCollection, RMGenFile.GenFileType whichFilePart, RMGenPart.eGender whichGender, RMGeneratorCollection parent) { log = new LogDataList(); log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedAutoData(parent.Parent.Name, path, RMCollectionType.Generator), _namespace); string[] listOfFiles = null; try { listOfFiles = Directory.GetFiles(path, "*" + RMPConstants.GenFileNamePrefixANDSuffix.PNG); } catch (Exception ex) { log.WriteErrorLog(LoggerMessages.RMPackage.Error.RetrieveAutoError(path, parent.Parent.Name, RMCollectionType.Generator), _namespace, ex); return; } if (listOfFiles == null || listOfFiles.Length == 0) { return; } string prefix; switch (whichFilePart) { case RMGenFile.GenFileType.Face: prefix = RMPConstants.GenFileNamePrefixANDSuffix.FACE_LOWER + RMPConstants.GenFileNamePrefixANDSuffix.SEPARATOR; break; case RMGenFile.GenFileType.SV: prefix = RMPConstants.GenFileNamePrefixANDSuffix.SV_LOWER + RMPConstants.GenFileNamePrefixANDSuffix.SEPARATOR; break; case RMGenFile.GenFileType.TV: prefix = RMPConstants.GenFileNamePrefixANDSuffix.TV_LOWER + RMPConstants.GenFileNamePrefixANDSuffix.SEPARATOR; break; case RMGenFile.GenFileType.TVD: prefix = RMPConstants.GenFileNamePrefixANDSuffix.TVD_LOWER + RMPConstants.GenFileNamePrefixANDSuffix.SEPARATOR; break; case RMGenFile.GenFileType.Var: prefix = RMPConstants.GenFileNamePrefixANDSuffix.VARIATION + RMPConstants.GenFileNamePrefixANDSuffix.SEPARATOR; break; default: return; } for (int i = 0; i < listOfFiles.Length; ++i) { string nonLoweredPath = listOfFiles[i]; listOfFiles[i] = listOfFiles[i].ToLower(); string fileName = Path.GetFileName(listOfFiles[i]); if (fileName.Length > prefix.Length && fileName.StartsWith(prefix)) { TempGenFileNameParsed tgfnm = null; try { tgfnm = new TempGenFileNameParsed(fileName, prefix.Length); VerifyFile(tgfnm, listOfFiles[i]); } catch (Exception ex) { log.WriteErrorLog(LoggerMessages.RMPackage.Error.InvalidGenFile(nonLoweredPath), _namespace, ex); continue; } RMGenPart tempPart = partsCollection.GetPartByInternalPosition(tgfnm.Part, whichGender, tgfnm.Position); RMGenFile newGenFile; string pathToSave = (trimRootPath) ? Helper.GetRelativePath(nonLoweredPath, rootPath) : nonLoweredPath; newGenFile = CreateGenFileFromTempGenFileName(tgfnm, GetProperFileType(tgfnm, whichFilePart), pathToSave); if (tempPart == null) { tempPart = CreateNewPart(tgfnm, whichGender, parent, (partsCollection.CountPartOfType(tgfnm.Part, whichGender) + 1)); partsCollection.Add(tempPart); } newGenFile.Parent = tempPart; tempPart.Files.Add(newGenFile); log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedFile(parent.Parent.Name, nonLoweredPath, RMCollectionType.Generator), _namespace); } } }