TreeNode AddFile(string path, RMTilesetGroup tilesetGroup, bool pathCanBeTrimmed = false)
        {
            string ext = Path.GetExtension(path).ToLower();

            RMTilesetFile tilesetFile = new RMTilesetFile(tilesetGroup);

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

            try
            {
                TilesetTypeAndName parsedFileName = new TilesetTypeAndName(Path.GetFileNameWithoutExtension(path));
                tilesetFile.AtlasType = parsedFileName.atlasType;
            }
            catch
            {
                tilesetFile.AtlasType = RMTilesetFile.eAtlasType.NotSpecified;
            }

            if (ext == RMPConstants.TilesetFileType.DOT_PNG)
            {
                tilesetFile.FileType = RMTilesetFile.eFileType.PNG;
            }
            else if (ext == RMPConstants.TilesetFileType.DOT_TEXT)
            {
                tilesetFile.FileType = RMTilesetFile.eFileType.Text;
            }
            else
            {
                throw new InvalidTilesetFileException(ExceptionMessages.General.FileExtInvalid(path), InvalidTilesetFileException.WhichInvalid.InvalidType, tilesetGroup);
            }
            TreeNode             tNode = new TreeNode();
            frmPackAssetTNodeTag tag   = new frmPackAssetTNodeTag(tNode, tilesetFile, RootDirectory);

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

            if (tilesetGroup.Files == null)
            {
                tilesetGroup.Files = new List <RMTilesetFile>();
            }
            tilesetGroup.Files.Add(tilesetFile);

            return(tNode);
        }
            public static RMTilesetCollection RetrieveTilesetCollection(string path, string rootPath, string _namespace, bool trimRootPath, out LogDataList log, RMPackage parent)
            {
                log = new LogDataList();
                RMTilesetCollection newCollection = new RMTilesetCollection(parent);

                log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedAutoData(parent.Name, path, RMCollectionType.Tilesets), _namespace);
                string[] files = null;
                try
                {
                    files = Directory.GetFiles(path);
                }catch (Exception ex)
                {
                    log.WriteErrorLog(LoggerMessages.RMPackage.Error.RetrieveAutoError(path, parent.Name, RMCollectionType.Tilesets), _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 fileExtension = Path.GetExtension(files[i]);
                    if (fileExtension.Length < RMPConstants.TilesetFileType.PNG.Length + 1)
                    {
                        continue;
                    }
                    fileExtension = fileExtension.Substring(1);

                    RMTilesetFile.eFileType typeOfFile = RMTilesetFile.eFileType.None;
                    typeOfFile = typeOfFile.ParseString(fileExtension);


                    if (typeOfFile == RMTilesetFile.eFileType.None || string.IsNullOrWhiteSpace(originalFileName))
                    {
                        continue;
                    }

                    TilesetTypeAndName parsedFileName = new TilesetTypeAndName(originalFileName);


                    RMTilesetGroup tileset = newCollection.Groups.FindByInternalName(parsedFileName.internalName);
                    if (tileset == null)
                    {
                        tileset              = new RMTilesetGroup(newCollection);
                        tileset.Name         = parsedFileName.Name;
                        tileset.internalName = parsedFileName.internalName;
                        newCollection.Groups.Add(tileset);
                    }
                    RMTilesetFile tilefile = new RMTilesetFile(tileset);
                    if (trimRootPath)
                    {
                        tilefile.Path = Helper.GetRelativePath(nonLoweredPath, rootPath);
                    }
                    else
                    {
                        tilefile.Path = nonLoweredPath;
                    }
                    tilefile.FileType  = typeOfFile;
                    tilefile.AtlasType = parsedFileName.atlasType;
                    tileset.Files.Add(tilefile);
                    log.WriteInformationLog(LoggerMessages.RMPackage.Info.RetrievedFile(parent.Name, nonLoweredPath, RMCollectionType.Tilesets), _namespace);
                }
                if (newCollection.Groups.Count == 0)
                {
                    return(null);
                }

                return(newCollection);
            }