예제 #1
0
        TreeNode AddFile(string path, RMSingleFileCollection sFCollection, bool pathCanBeTrimmed = false)
        {
            RMSingleFile singleFile = new RMSingleFile(sFCollection);

            singleFile.FileName = Path.GetFileName(path);
            if (pathCanBeTrimmed)
            {
                singleFile.Path = Helper.GetRelativePath(path, RootDirectory);
            }
            else
            {
                singleFile.Path = path;
                //singleFile.NonRelativePath = true;
            }

            TreeNode             tNode = new TreeNode();
            frmPackAssetTNodeTag tag   = new frmPackAssetTNodeTag(tNode, singleFile, RootDirectory);

            tNode.Text = tag.ToString();
            tNode.Tag  = tag;

            if (sFCollection.Files == null)
            {
                sFCollection.Files = new List <RMSingleFile>();
            }
            sFCollection.Files.Add(singleFile);

            return(tNode);
        }
        public RMSingleFile Clone(RMSingleFileCollection parent)
        {
            RMSingleFile clone = new RMSingleFile(parent);

            clone.FileName           = FileName;
            clone.InstallationStatus = InstallationStatus;
            clone.InternalFileName   = InternalFileName;
            clone.Path  = Path;
            clone._path = _path;
            return(clone);
        }
            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 RMSingleFile(XElement whichElement, RMSingleFileCollection parent)
        {
            Parent = parent;
            string path = whichElement.Value;

            Path     = path;
            FileName = System.IO.Path.GetFileNameWithoutExtension(path);
            if (parent.Parent.Installed)
            {
                XAttribute installedAttr = whichElement.Attribute(RMPConstants.ATTR_INSTALLED);
                if ((string)installedAttr != null)
                {
                    InstallationStatus = Pacman.Helper.GetInstallStatus(installedAttr.Value);
                }
            }
        }
 public RMSingleFile(RMSingleFileCollection parent)
 {
     Parent = parent;
 }
예제 #6
0
        TreeNode AddFile(TreeNode selectedNode, string path, string _namespace, bool skipSanityChecks = false, bool pathCanBeTrimmed = false)
        {
            if (!skipSanityChecks)
            {
                if (string.IsNullOrWhiteSpace(path))
                {
                    throw new FileNotFoundException(ExceptionMessages.GUI.frmPackageAssets.FILE_PATH_NULL);
                }

                if (!File.Exists(path))
                {
                    throw new FileNotFoundException(ExceptionMessages.General.FileNotFound(path));
                }
                if (!string.IsNullOrWhiteSpace(RootDirectory) && path.ToLower().StartsWith(RootDirectory.ToLower()))
                {
                    pathCanBeTrimmed = true;
                }
            }



            frmPackAssetTNodeTag parentingTag = selectedNode.Tag as frmPackAssetTNodeTag;

            if (parentingTag == null)
            {
                throw new NullReferenceException(ExceptionMessages.GUI.frmPackageAssets.TAG_SEL_NODE_NULL);
            }

            if (parentingTag.TagObjectType == frmPackAssetTNodeTag.TagType.AudioGroup)
            {
                RMAudioGroup audioGroup = parentingTag.Object as RMAudioGroup;
                if (audioGroup == null)
                {
                    throw new NullReferenceException(ExceptionMessages.GUI.frmPackageAssets.ASSOC_OBJ_TAG_SEL_NODE_NULL);
                }
                TreeNode tNode = AddFile(path, audioGroup, pathCanBeTrimmed);
                parentingTag.AssociatedNode.Nodes.Add(tNode);
                return(tNode);
            }
            else if (parentingTag.TagObjectType == frmPackAssetTNodeTag.TagType.CharacterGroup)
            {
                RMCharImageGroup charNode = parentingTag.Object as RMCharImageGroup;
                if (charNode == null)
                {
                    throw new NullReferenceException(ExceptionMessages.GUI.frmPackageAssets.ASSOC_OBJ_TAG_SEL_NODE_NULL);
                }
                TreeNode tNode = AddFile(path, charNode, pathCanBeTrimmed);
                parentingTag.AssociatedNode.Nodes.Add(tNode);
                return(tNode);
            }
            else if (parentingTag.TagObjectType == frmPackAssetTNodeTag.TagType.Collection)
            {
                RMSingleFileCollection singleFileC = parentingTag.Object as RMSingleFileCollection;
                if (singleFileC == null)
                {
                    throw new NullReferenceException(ExceptionMessages.GUI.frmPackageAssets.ASSOC_OBJ_TAG_SEL_NODE_NULL);
                }
                TreeNode tNode = AddFile(path, singleFileC, pathCanBeTrimmed);
                parentingTag.AssociatedNode.Nodes.Add(tNode);

                if (!PackageOfCollections.Collections.Contains(singleFileC))
                {
                    PackageOfCollections.Collections.Add(singleFileC);
                }

                return(tNode);
            }
            else if (parentingTag.TagObjectType == frmPackAssetTNodeTag.TagType.GeneratorPartGroup)
            {
                RMGenPart genGroup = parentingTag.Object as RMGenPart;
                if (genGroup == null)
                {
                    throw new NullReferenceException(ExceptionMessages.GUI.frmPackageAssets.ASSOC_OBJ_TAG_SEL_NODE_NULL);
                }
                TreeNode tNode = AddFile(path, genGroup, pathCanBeTrimmed);
                parentingTag.AssociatedNode.Nodes.Add(tNode);
                return(tNode);
            }
            else if (parentingTag.TagObjectType == frmPackAssetTNodeTag.TagType.MovieGroup)
            {
                RMMovieGroup movieGroup = parentingTag.Object as RMMovieGroup;
                if (movieGroup == null)
                {
                    throw new NullReferenceException(ExceptionMessages.GUI.frmPackageAssets.ASSOC_OBJ_TAG_SEL_NODE_NULL);
                }
                TreeNode tNode = AddFile(path, movieGroup, pathCanBeTrimmed);
                parentingTag.AssociatedNode.Nodes.Add(tNode);
                return(tNode);
            }
            else if (parentingTag.TagObjectType == frmPackAssetTNodeTag.TagType.TilesetGroup)
            {
                RMTilesetGroup tilesetGroup = parentingTag.Object as RMTilesetGroup;
                if (tilesetGroup == null)
                {
                    throw new NullReferenceException(ExceptionMessages.GUI.frmPackageAssets.ASSOC_OBJ_TAG_SEL_NODE_NULL);
                }
                TreeNode tNode = AddFile(path, tilesetGroup, pathCanBeTrimmed);
                parentingTag.AssociatedNode.Nodes.Add(tNode);
                return(tNode);
            }
            else
            {
                TreeNode parentingNode = parentingTag.AssociatedNode.Parent;
                if (parentingNode == null)
                {
                    throw new NullReferenceException(ExceptionMessages.GUI.frmPackageAssets.PARENT_NODE_NULL);
                }
                return(AddFile(parentingNode, path, _namespace, true, pathCanBeTrimmed));
            }
        }
                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;
                }
            }
        }