public static RMCollectionType ToRMCollectionType(this RMSingleFileCollection.CollectionType typeOfCollection) { switch (typeOfCollection) { case RMSingleFileCollection.CollectionType.Animation: return(RMCollectionType.Animation); case RMSingleFileCollection.CollectionType.BattleBacks_1: return(RMCollectionType.BattleBacks_1); case RMSingleFileCollection.CollectionType.BattleBacks_2: return(RMCollectionType.BattleBacks_2); case RMSingleFileCollection.CollectionType.Data: return(RMCollectionType.Data); case RMSingleFileCollection.CollectionType.Parallax: return(RMCollectionType.Parallaxes); case RMSingleFileCollection.CollectionType.Pictures: return(RMCollectionType.Pictures); case RMSingleFileCollection.CollectionType.Plugins: return(RMCollectionType.Plugins); case RMSingleFileCollection.CollectionType.System: return(RMCollectionType.System_Image); case RMSingleFileCollection.CollectionType.Titles_1: return(RMCollectionType.Titles1); default: return(RMCollectionType.Titles2); } }
public static string ToFileExtension(this RMSingleFileCollection.CollectionType typeOfCollection) { switch (typeOfCollection) { case RMSingleFileCollection.CollectionType.Data: return(RMPConstants.MiscFileExtensions.JSON); case RMSingleFileCollection.CollectionType.Plugins: return(RMPConstants.MiscFileExtensions.JAVASCRIPT); default: return(RMPConstants.MiscFileExtensions.PNG); } }
public static RMSingleFileCollection ToNewClassInstance(this RMSingleFileCollection.CollectionType typeOfCollection, RMPackage parent) { RMSingleFileCollection newCollection; switch (typeOfCollection) { case RMSingleFileCollection.CollectionType.Animation: newCollection = new RMAnimationCollection(parent); newCollection.Name = RMPConstants.Defaults.ANIM_COLLECTION_NAME; break; case RMSingleFileCollection.CollectionType.Data: newCollection = new RMDataCollection(parent); newCollection.Name = RMPConstants.Defaults.DATA_COLLECTION_NAME; break; case RMSingleFileCollection.CollectionType.BattleBacks_1: newCollection = new RMBattleBacks1_Collection(parent); newCollection.Name = RMPConstants.Defaults.BB1_COLLECTION_NAME; break; case RMSingleFileCollection.CollectionType.BattleBacks_2: newCollection = new RMBattleBacks2_Collection(parent); newCollection.Name = RMPConstants.Defaults.BB2_COLLECTION_NAME; break; case RMSingleFileCollection.CollectionType.Parallax: newCollection = new RMParallaxCollection(parent); newCollection.Name = RMPConstants.Defaults.PARALLAX_COLLECTION_NAME; break; case RMSingleFileCollection.CollectionType.Pictures: newCollection = new RMPictureCollection(parent); newCollection.Name = RMPConstants.Defaults.PICTURES_COLLECTION_NAME; break; case RMSingleFileCollection.CollectionType.System: newCollection = new RMSysImageCollection(parent); newCollection.Name = RMPConstants.Defaults.SYSTEM_COLLECTION_NAME; break; case RMSingleFileCollection.CollectionType.Titles_1: newCollection = new RMTitles1_Collection(parent); newCollection.Name = RMPConstants.Defaults.TITLES1_COLLECTION_NAME; break; case RMSingleFileCollection.CollectionType.Titles_2: newCollection = new RMTitles2_Collection(parent); newCollection.Name = RMPConstants.Defaults.TITLES2_COLLECTION_NAME; break; case RMSingleFileCollection.CollectionType.Plugins: newCollection = new RMPluginsCollection(parent); newCollection.Name = RMPConstants.Defaults.PLUGINS_COLLECTION_NAME; break; default: newCollection = null; break; } return(newCollection); }
public static string ToDirectoryName(this RMSingleFileCollection.CollectionType collectionType, bool fullPath = true) { switch (collectionType) { case RMSingleFileCollection.CollectionType.Animation: if (fullPath) { return(DirectoryNames.ProjectFiles.Image.ROOT + "\\" + DirectoryNames.ProjectFiles.Image.ANIMATION); } else { return(DirectoryNames.ProjectFiles.Image.ANIMATION); } case RMSingleFileCollection.CollectionType.BattleBacks_1: if (fullPath) { return(DirectoryNames.ProjectFiles.Image.ROOT + "\\" + DirectoryNames.ProjectFiles.Image.BATTLEBACKS_1); } else { return(DirectoryNames.ProjectFiles.Image.BATTLEBACKS_1); } case RMSingleFileCollection.CollectionType.BattleBacks_2: if (fullPath) { return(DirectoryNames.ProjectFiles.Image.ROOT + "\\" + DirectoryNames.ProjectFiles.Image.BATTLEBACKS_2); } else { return(DirectoryNames.ProjectFiles.Image.BATTLEBACKS_2); } case RMSingleFileCollection.CollectionType.Data: return(DirectoryNames.ProjectFiles.DATA); case RMSingleFileCollection.CollectionType.Parallax: if (fullPath) { return(DirectoryNames.ProjectFiles.Image.ROOT + "\\" + DirectoryNames.ProjectFiles.Image.PARALLAXES); } else { return(DirectoryNames.ProjectFiles.Image.PARALLAXES); } case RMSingleFileCollection.CollectionType.Pictures: if (fullPath) { return(DirectoryNames.ProjectFiles.Image.ROOT + "\\" + DirectoryNames.ProjectFiles.Image.PICTURES); } else { return(DirectoryNames.ProjectFiles.Image.PICTURES); } case RMSingleFileCollection.CollectionType.Plugins: return(DirectoryNames.ProjectFiles.PLUGINS); case RMSingleFileCollection.CollectionType.System: if (fullPath) { return(DirectoryNames.ProjectFiles.Image.ROOT + "\\" + DirectoryNames.ProjectFiles.Image.SYSTEM); } else { return(DirectoryNames.ProjectFiles.Image.SYSTEM); } case RMSingleFileCollection.CollectionType.Titles_1: if (fullPath) { return(DirectoryNames.ProjectFiles.Image.ROOT + "\\" + DirectoryNames.ProjectFiles.Image.TITLES_1); } else { return(DirectoryNames.ProjectFiles.Image.TITLES_1); } case RMSingleFileCollection.CollectionType.Titles_2: if (fullPath) { return(DirectoryNames.ProjectFiles.Image.ROOT + "\\" + DirectoryNames.ProjectFiles.Image.TITLES_2); } else { return(DirectoryNames.ProjectFiles.Image.TITLES_2); } default: return(string.Empty); } }
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 void InstallSingleFileCollection(string toWhere, string fromRootDirectory, RMSingleFileCollection.CollectionType collectionType, RMSingleFileCollection collection, string _namespace) { string collType = collectionType.ToDirectoryName(); if (string.IsNullOrWhiteSpace(collType)) { try { throw new InvalidSingleFileCollectionException(ExceptionMessages.RMPackage.COLL_NO_TYPE, InvalidSingleFileCollectionException.WhichInvalid.NoType, collection.Parent); } catch (Exception ex) { Logger.WriteErrorLog(LoggerMessages.PackageManagement.Installer.Error.UNABLE_INSTALL_SF_NO_TYPE, _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } } string dirPath = toWhere + "\\" + collType; Helper.MakeDirIfNotExistInstall(dirPath, _namespace); if (collection.Files != null) { foreach (RMSingleFile singleFile in collection.Files) { if (string.IsNullOrWhiteSpace(singleFile.Path)) { try { throw new InvalidSingleFileException(ExceptionMessages.RMPackage.FILE_PATH_NULL); } catch (Exception ex) { Logger.WriteErrorLog(LoggerMessages.PackageManagement.Installer.Error.UNABLE_INSTALL_SF_NO_PATH, _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } } string fileName = Path.GetFileName(singleFile.Path); string newFile = dirPath + "\\" + fileName; string oldFile = fromRootDirectory + "\\" + singleFile.Path; Exception outEx; if (Helper.CopyFileSafely(oldFile, newFile, true, _namespace, out outEx, new CopyFileLogMessages(copyFileFailed: LoggerMessages.PackageManagement.Installer.Error.UnableInstallSFCopyFailed)) != CopyFileResult.Success) { throw outEx; } //singleFile.InstallationStatus = RMPackObject.InstallStatus.Installed; singleFile.Path = Helper.GetRelativePath(newFile, toWhere); } } }
static void CopySingleFileCollection(string toWhere, RMSingleFileCollection.CollectionType collectionType, RMSingleFileCollection collection, string _namespace, string rootDir = null) { string collType = collectionType.ToDirectoryName(); if (string.IsNullOrWhiteSpace(collType)) { try { throw new InvalidSingleFileCollectionException(ExceptionMessages.RMPackage.COLL_NO_TYPE, InvalidSingleFileCollectionException.WhichInvalid.NoType, collection.Parent); } catch (Exception ex) { Logger.WriteErrorLog(LoggerMessages.PackageMaker.Error.COLLECTION_NO_TYPE, _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } } string dirPath = toWhere + "\\" + collType; Helper.MakeDirIfNotExistCopy(dirPath, _namespace); if (collection.Files == null) { return; } foreach (RMSingleFile singleFile in collection.Files) { if (string.IsNullOrWhiteSpace(rootDir) && singleFile.NonRootedPath) { try { throw new InvalidPathException(ExceptionMessages.PackUtil.FILE_PATH_REL, singleFile.Path); } catch (Exception ex) { Logger.WriteErrorLog(LoggerMessages.PackageMaker.Error.FILE_ALREADY_RELATIVE + singleFile.Path + ".", _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } } if (string.IsNullOrWhiteSpace(singleFile.Path)) { try { throw new InvalidSingleFileException(ExceptionMessages.RMPackage.FILE_PATH_NULL); } catch (Exception ex) { Logger.WriteErrorLog(LoggerMessages.PackageMaker.Error.FILE_PATH_NOT_SET, _namespace, ex, BasicDebugLogger.DebugErrorType.Error); throw; } } string fileName = Path.GetFileName(singleFile.Path); string newFile = dirPath + "\\" + fileName; string originFile = singleFile.Path; if (!string.IsNullOrWhiteSpace(rootDir)) { originFile = rootDir + "\\" + singleFile.Path; } Exception outEx; if (Helper.CopyFileSafely(originFile, newFile, true, _namespace, out outEx, new CopyFileLogMessages(copyFileFailed: LoggerMessages.PackageUtil.Error.CopyFileFailed)) != CopyFileResult.Success) { throw outEx; } } }