Exemplo n.º 1
0
        private string MakeDestinationFile(AssetTypeEnum assetType, string s, AssetFileEnum fileType, int fileNumber)
        {
            bool unrootedOther = (assetType == AssetTypeEnum.Other || fileType == AssetFileEnum.Other) &&
                                 !Path.IsPathRooted(s);
            string directory = unrootedOther ? Path.GetDirectoryName(s) :
                               AssetFile.DirectoryForFileEnum(assetType, fileNumber == 0, fileType);
            string targetFile = directory + "\\" + Path.GetFileName(s);

            return(targetFile);
        }
 public static string ExtensionForEnum(AssetFileEnum fileTypeEnum)
 {
     foreach (ExtensionMapping mapping in extensionMappings) {
         if (mapping.FileTypeEnum == fileTypeEnum)
             return mapping.FileExtension;
     }
     return "";
 }
        public static string DirectoryForFileEnum(AssetTypeEnum type, bool primaryFile, 
												  AssetFileEnum fileTypeEnum)
        {
            foreach (ExtensionMapping mapping in extensionMappings) {
                if ((fileTypeEnum == mapping.FileTypeEnum) &&
                    (type == mapping.AssetType || mapping.AssetType == AssetTypeEnum.None) &&
                    (mapping.PrimaryMatch == ExtensionPrimaryEnum.DontCare ||
                     (mapping.PrimaryMatch == ExtensionPrimaryEnum.MatchPrimary) == primaryFile))
                    return mapping.AssetDirectory;
            }
            return "Misc";
        }
 public static string AssetFileEnumName(AssetFileEnum e)
 {
     return assetFileEnumNames[(int)e];
 }
 // Returns all extensions
 public static List<string> AllExtensionsForEnum(AssetFileEnum fileTypeEnum)
 {
     List<string> strings = new List<string>();
     foreach (ExtensionMapping mapping in extensionMappings) {
         if (mapping.AssetType == AssetTypeEnum.None && mapping.FileTypeEnum == fileTypeEnum)
             strings.Add(mapping.FileExtension);
     }
     return strings;
 }
 public AssetFile(string targetFile, AssetFileEnum fileTypeEnum)
 {
     this.targetFile = targetFile;
     this.fileTypeEnum = fileTypeEnum;
     newFileName = "";
 }
 public AssetFile()
 {
     targetFile = "";
     newFileName = "";
     fileTypeEnum = AssetFileEnum.None;
 }
 protected void BuildSingleFileAssets(string dir, AssetTypeEnum assetType, AssetFileEnum fileType)
 {
     List<string> extensions = AssetFile.AllExtensionsForEnum(fileType);
     DirectoryInfo info = new DirectoryInfo(MakeRepositoryFilePath(dir));
     FileInfo[] files = info.GetFiles();
     foreach (FileInfo fileInfo in files) {
         string extension = fileInfo.Extension.ToLower();
         if (extensions.IndexOf(extension) < 0)
             continue;
         string baseName = Path.GetFileNameWithoutExtension(fileInfo.Name) + "_" +
             AssetTypeDesc.AssetTypeEnumFileName(assetType);
         string defPath = MakeRepositoryFilePath("AssetDefinitions\\" + baseName + ".asset");
         if (new FileInfo(defPath).Exists) {
             Warn("Skipping generated of asset definition '{0}', because it already exists", defPath);
             continue;
         }
         AssetFile file = new AssetFile(MakeFullFilePath(dir, fileInfo.Name), fileType);
         AssetDefinition def = new AssetDefinition(baseName, assetType, file);
         def.SetDescriptionFromName();
         def.WriteXmlFile(defPath);
     }
 }
 protected List<AssetDefinition> FindAssetsWithPrimaryFileName(string file, AssetFileEnum fileType, List<string> log)
 {
     List<AssetDefinition> assets;
     string dir = AssetFile.DirectoryForFileEnum(AssetTypeEnum.None, true, fileType);
     string fullFile = MakeFullFilePath(dir, file);
     if (assetsWithPrimaryFileName.TryGetValue(fullFile, out assets))
         return assets;
     else {
         log.Add(string.Format("Couldn't find assets based on file '{0}'", file));
         return new List<AssetDefinition>();
     }
 }
        public ExtensionMapping(AssetTypeEnum assetType, bool primaryMatch, string fileExtension,
								string assetDirectory, AssetFileEnum fileTypeEnum)
        {
            this.primaryMatchEnum = (primaryMatch ? ExtensionPrimaryEnum.MatchPrimary :
                                     ExtensionPrimaryEnum.DontMatchPrimary);
            this.typeEnum = assetType;
            this.fileExtension = fileExtension;
            this.assetDirectory = assetDirectory;
            this.fileTypeEnum = fileTypeEnum;
        }
        protected void AddParsedReferences(AssetDefinition def, string referee, List<string> references,
										   Dictionary<string, List<string>> introducers, string introducer,
										   AssetTypeEnum assetType, AssetFileEnum fileType)
        {
            List<string> usedNames;
            if (introducers.TryGetValue(introducer, out usedNames)) {
                string dir = AssetFile.DirectoryForFileEnum(assetType, false, fileType);
                foreach (string referredTo in usedNames) {
                    string referredToFile = MakeFullFilePath(dir, referredTo);
                    if (references.IndexOf(referredToFile) >= 0)
                        continue;
                    if (!new FileInfo(MakeRepositoryFilePath(referredToFile)).Exists) {
                        Warn("Skipping file '{0}', referenced by '{1}', because the file does not exist",
                             referredToFile, referee);
                        continue;
                    }
                    references.Add(referredToFile);
                    AssetFile assetFile = new AssetFile(referredToFile, fileType);
                    def.Files.Add(assetFile);
                }
            }
        }
        public ExtensionMapping(AssetTypeEnum assetType, string fileExtension,
								string assetDirectory, AssetFileEnum fileTypeEnum)
        {
            this.primaryMatchEnum = ExtensionPrimaryEnum.DontCare;
            this.typeEnum = assetType;
            this.fileExtension = fileExtension;
            this.assetDirectory = assetDirectory;
            this.fileTypeEnum = fileTypeEnum;
        }
 public AssetTypeFileDesc(AssetFileEnum fileTypeEnum, int minCount, int maxCount)
 {
     this.additionalText = "";
     this.fileTypeEnum = fileTypeEnum;
     this.minCount = minCount;
     this.maxCount = maxCount;
 }
Exemplo n.º 14
0
 private string MakeDestinationFile(AssetTypeEnum assetType, string s, AssetFileEnum fileType, int fileNumber)
 {
     bool unrootedOther = (assetType == AssetTypeEnum.Other || fileType == AssetFileEnum.Other) &&
                          !Path.IsPathRooted(s);
     string directory = unrootedOther ? Path.GetDirectoryName(s) :
         AssetFile.DirectoryForFileEnum(assetType, fileNumber == 0, fileType);
     string targetFile = directory + "\\" + Path.GetFileName(s);
     return targetFile;
 }
 protected static string CompressedFileEnumName(AssetFileEnum e)
 {
     return compressedAssetFileEnumNames[(int)e];
     //return e.ToString();
 }
 public int CountFilesOfType(AssetFileEnum fileTypeEnum)
 {
     int cnt = 0;
     foreach(AssetFile desc in files) {
         if (desc.FileTypeEnum == fileTypeEnum)
             cnt++;
     }
     return cnt;
 }
 protected void FromXmlInternal(XmlReader r, List<string> log)
 {
     while(r.Read())
     {
         if (r.NodeType == XmlNodeType.EndElement)
         {
             break;
         }
         if (r.NodeType == XmlNodeType.Whitespace)
         {
             continue;
         }
         switch(r.Name)
         {
             case "TargetFile":
                 targetFile = r.ReadElementString();
                 break;
             case "NewFileName":
                 newFileName = r.ReadElementString();
                 break;
             case "FileType":
                 fileTypeEnum = AssetFileEnumFromCompressedName(r.ReadElementString());
                 break;
             default:
                 log.Add(string.Format("In AssetFile.FromXmlInternal, unknown attribute '{0}'", r.Name));
                 break;
         }
     }
 }
 protected void FromXmlInternal(XmlElement root, List<string> log)
 {
     XmlElement child = (XmlElement)root.FirstChild;
     while (child != null) {
         switch (child.LocalName) {
             case "TargetFile":
                 targetFile = child.InnerText.Replace('\\', Path.DirectorySeparatorChar);
                 break;
             case "NewFileName":
                 newFileName = child.InnerText.Replace('\\', Path.DirectorySeparatorChar);
                 break;
             case "FileType":
                 fileTypeEnum = AssetFileEnumFromCompressedName(child.InnerText);
                 break;
             default:
                 log.Add(string.Format("In AssetFile.FromXmlInternal, unknown attribute '{0}'", child.LocalName));
                 break;
         }
         child = (XmlElement)child.NextSibling;
     }
 }