Beispiel #1
0
 public FileType GetFileType(string path, string siblingPath = null)
 {
     if (path.Contains("&"))
     {
         path = path.Split('&')[0];
     }
     if (siblingPath != null)
     {
         if (siblingPath.StartsWith("FlexDMD.Resources."))
         {
             path = "FlexDMD.Resources." + path;
         }
         else if (siblingPath.StartsWith("VPX."))
         {
             path = "VPX." + path;
         }
         else
         {
             path = Path.Combine(siblingPath, "..", path);
         }
     }
     if (path.StartsWith("FlexDMD.Resources."))
     {
         return(GetTypeFromExt(path));
     }
     else if (path.StartsWith("VPX."))
     {
         if (_vpxFile == null && TableFile != null && File.Exists(Path.Combine(BasePath, TableFile)))
         {
             _vpxFile = new VPXFile(Path.Combine(BasePath, TableFile));
         }
         if (_vpxFile != null)
         {
             var file = _vpxFile.GetImportFile(GetVPXId(path));
             if (file != null)
             {
                 return(GetTypeFromExt(file));
             }
         }
         return(FileType.Unknow);
     }
     else
     {
         var fullPath = Path.Combine(BasePath, path);
         return(GetTypeFromExt(fullPath));
     }
 }
Beispiel #2
0
 public bool FileExists(string path, string siblingPath = null)
 {
     if (path.Contains("&"))
     {
         path = path.Split('&')[0];
     }
     if (siblingPath != null)
     {
         if (siblingPath.StartsWith("FlexDMD.Resources."))
         {
             path = "FlexDMD.Resources." + path;
         }
         else if (siblingPath.StartsWith("VPX."))
         {
             path = "VPX." + path;
         }
         else
         {
             path = Path.Combine(siblingPath, "..", path);
         }
     }
     if (path.StartsWith("FlexDMD.Resources."))
     {
         return(Assembly.GetExecutingAssembly().GetManifestResourceInfo(path) != null);
     }
     else if (path.StartsWith("VPX."))
     {
         // TODO do not keept the file open (this blocks editing)
         if (_vpxFile == null && TableFile != null && File.Exists(Path.Combine(BasePath, TableFile)))
         {
             _vpxFile = new VPXFile(Path.Combine(BasePath, TableFile));
         }
         if (_vpxFile != null)
         {
             return(_vpxFile.Contains(GetVPXId(path)));
         }
         return(false);
     }
     else
     {
         var fullPath = Path.Combine(BasePath, path);
         return(File.Exists(fullPath));
     }
 }
Beispiel #3
0
 /// <summary>
 /// Resolve then open a stream for the given path. It is the responsibility of the caller to close the stream.
 ///
 /// File names are resolved using the following rules:
 /// <list type="bullet">
 /// <item>
 /// <description>If the file name starts with 'FlexDMD.Resources.' then the file is searched inside FlexDMD's embedded resources,</description>
 /// </item>
 /// <item>
 /// <description>If the file name starts with 'VPX.' then the file is searched inside the VPX table file,</description>
 /// </item>
 /// <item>
 /// <description>Otherwise, the file is searched in the project folder (see FlexDMD.SetProjectFolder).</description>
 /// </item>
 /// </list>
 ///
 /// Note that for the time being, for videos, only files placed in the project folder are supported.
 ///
 /// </summary>
 public Stream OpenStream(string path, string siblingPath = null)
 {
     if (path.Contains("&"))
     {
         path = path.Split('&')[0];
     }
     if (siblingPath != null)
     {
         if (siblingPath.StartsWith("FlexDMD.Resources."))
         {
             path = "FlexDMD.Resources." + path;
         }
         else if (siblingPath.StartsWith("VPX."))
         {
             path = "VPX." + path;
         }
         else
         {
             path = Path.Combine(siblingPath, "..", path);
         }
     }
     if (path.StartsWith("FlexDMD.Resources."))
     {
         return(Assembly.GetExecutingAssembly().GetManifestResourceStream(path));
     }
     else if (path.StartsWith("VPX."))
     {
         if (_vpxFile == null && TableFile != null && File.Exists(Path.Combine(BasePath, TableFile)))
         {
             _vpxFile = new VPXFile(Path.Combine(BasePath, TableFile));
         }
         if (_vpxFile != null)
         {
             return(_vpxFile.OpenStream(GetVPXId(path)));
         }
         return(null);
     }
     else
     {
         var fullPath = Path.Combine(BasePath, path);
         return(new FileStream(fullPath, FileMode.Open, FileAccess.Read));
     }
 }