public string RequestDependency(string dependency)
        {
            if (Files.TryGetValue(dependency, out string dependencyPath))
            {
                return(dependencyPath);
            }

            foreach (string dataPath in DataPathes)
            {
                string filePath = Path.Combine(dataPath, dependency);
                if (FileMultiStream.Exists(filePath))
                {
                    return(filePath);
                }

                if (FilenameUtils.IsDefaultResource(dependency))
                {
                    return(FindEngineDependency(dataPath, FilenameUtils.DefaultResourceName1) ??
                           FindEngineDependency(dataPath, FilenameUtils.DefaultResourceName2));
                }
                else if (FilenameUtils.IsBuiltinExtra(dependency))
                {
                    return(FindEngineDependency(dataPath, FilenameUtils.BuiltinExtraName1) ??
                           FindEngineDependency(dataPath, FilenameUtils.BuiltinExtraName2));
                }
            }
            return(null);
        }
        protected void CollectGameFiles(DirectoryInfo root, IDictionary <string, string> files)
        {
            string filePath = Path.Combine(root.FullName, GlobalGameManagerName);

            if (FileMultiStream.Exists(filePath))
            {
                AddFile(files, GlobalGameManagerName, filePath);
            }
            else
            {
                filePath = Path.Combine(root.FullName, MainDataName);
                if (FileMultiStream.Exists(filePath))
                {
                    AddFile(files, MainDataName, filePath);
                }
            }

            foreach (FileInfo levelFile in root.EnumerateFiles())
            {
                if (s_levelName.IsMatch(levelFile.Name))
                {
                    string levelName = FileMultiStream.GetFileName(levelFile.Name);
                    AddFile(files, levelName, levelFile.FullName);
                }
            }
        }
 public string RequestResource(string resource)
 {
     foreach (string dataPath in DataPathes)
     {
         string path = Path.Combine(dataPath, resource);
         if (FileMultiStream.Exists(path))
         {
             return(path);
         }
     }
     return(null);
 }
Exemple #4
0
        public static ResourceFileScheme LoadScheme(string filePath, string fileName)
        {
            if (!FileMultiStream.Exists(filePath))
            {
                throw new Exception($"Resource file at path '{filePath}' doesn't exist");
            }

            using (SmartStream stream = SmartStream.OpenRead(filePath))
            {
                return(ReadScheme(stream, 0, stream.Length, filePath, fileName));
            }
        }
 public bool RequestResource(string resource, out string path)
 {
     foreach (string dataPath in DataPathes)
     {
         path = Path.Combine(dataPath, resource);
         if (FileMultiStream.Exists(path))
         {
             return(true);
         }
     }
     path = null;
     return(false);
 }
		public bool RequestDependency(string dependency)
		{
			if(Files.TryGetValue(dependency, out string dependencyPath))
			{
				LoadDependency(dependency, dependencyPath);
				return true;
			}

			foreach (string dataPath in DataPathes)
			{
				string filePath = Path.Combine(dataPath, dependency);
				if (FileMultiStream.Exists(filePath))
				{
					LoadDependency(dependency, filePath);
					return true;
				}

				if (FilenameUtils.IsDefaultResource(dependency))
				{
					if (LoadEngineDependency(dataPath, FilenameUtils.DefaultResourceName1))
					{
						return true;
					}
					if (LoadEngineDependency(dataPath, FilenameUtils.DefaultResourceName2))
					{
						return true;
					}
				}
				else if (FilenameUtils.IsBuiltinExtra(dependency))
				{
					if (LoadEngineDependency(dataPath, FilenameUtils.BuiltinExtraName1))
					{
						return true;
					}
					if (LoadEngineDependency(dataPath, FilenameUtils.BuiltinExtraName2))
					{
						return true;
					}
				}
			}
			return false;
		}
Exemple #7
0
        public MixedGameStructure(FileCollection collection, IEnumerable <string> pathes) :
            base(collection)
        {
            Dictionary <string, string> files      = new Dictionary <string, string>();
            Dictionary <string, string> assemblies = new Dictionary <string, string>();
            HashSet <string>            dataPathes = new HashSet <string>();

            foreach (string path in pathes)
            {
                if (FileMultiStream.Exists(path))
                {
                    string name = FileMultiStream.GetFileName(path);
                    files.Add(name, path);
                    string directory = Path.GetDirectoryName(path);
                    dataPathes.Add(directory);
                }
                else if (DirectoryUtils.Exists(path))
                {
                    DirectoryInfo directory = new DirectoryInfo(DirectoryUtils.ToLongPath(path));
                    CollectFromDirectory(directory, files, assemblies, dataPathes);
                }
                else
                {
                    throw new Exception($"Neither file nor directory at '{path}' exists");
                }
            }

            if (files.Count == 0)
            {
                throw new Exception("No files has been found");
            }

            DataPathes = dataPathes.ToArray();
            Files      = files;
            Assemblies = assemblies;
            SetScriptingBackend();
            Name = Files.First().Key;
        }
 private IEnumerable <string> SelectUniquePathes(IEnumerable <string> pathes)
 {
     return(pathes.Select(t => FileMultiStream.GetFilePath(t)).Distinct());
 }