Example #1
0
        /// <summary>
        /// Determines whether the specified file exists.
        /// </summary>
        /// <param name="path">The file to check.</param>
        /// <returns><b>true</b> if the file is exists; otherwise, <b>false</b>.</returns>
        public static bool Exists(string path)
        {
            //!!!!bool useCache/resetCache. можно же просто Dictionary сделать

            if (!VirtualFileSystem.initialized)
            {
                Log.Fatal("VirtualFileSystem: File system is not initialized.");
            }

            if (VirtualFileSystem.LoggingFileOperations)
            {
                Log.Info("Logging file operations: VirtualFile.Exists( \"{0}\" )", path);
            }

            string realPath = VirtualPathUtility.GetRealPathByVirtual(path);

            if (File.Exists(realPath))
            {
                return(true);
            }

            if (ArchiveManager.FileExists(path))
            {
                return(true);
            }

            return(false);

            //!!!!!всё закомменченное

            //lock( VirtualFileSystem.lockObject )
            //{
            //	path = VirtualPathUtils.NormalizePath( path );

            //	path = VirtualFileSystem.GetRedirectedFileNameInternal( path, true );

            //	string realPath = VirtualPathUtils.GetRealPathByVirtual( path );
            //	if( File.Exists( realPath ) )
            //		return true;

            //	if( InsidePackage( path ) )
            //		return true;

            //	return false;
            //}
        }
Example #2
0
        public static bool Init(string logFileName, bool setCurrentDirectory, string projectDirectory,
                                string userSettingsDirectory, string overrideBinariesDirectory = null)
        {
            if (initialized)
            {
                Log.Fatal("VirtualFileSystem: Init: File system is already initialized.");
                return(false);
            }

            //it can be already started
            StartupTiming.TotalStart();

            StartupTiming.CounterStart("Initialize virtual file system");
            try
            {
                mainThread = Thread.CurrentThread;

                //init directories
                {
                    if (string.IsNullOrEmpty(projectDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Project directory must be specified.");
                    }
                    if (!Directory.Exists(projectDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Specified project directory is not exists.");
                    }
                    projectDirectory    = VirtualPathUtility.NormalizePath(projectDirectory);
                    Directories.project = projectDirectory;
                    if (!Path.IsPathRooted(Directories.project))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Project directory path must be rooted.");
                        return(false);
                    }

                    Directories.assets = Path.Combine(Directories.project, "Assets");
                    if (string.IsNullOrEmpty(Directories.assets))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Project Assets directory must be specified.");
                    }
                    if (!Directory.Exists(Directories.assets))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Specified project Assets directory is not exists.");
                    }

                    if (string.IsNullOrEmpty(userSettingsDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: User settings directory must be specified.");
                    }
                    if (!Path.IsPathRooted(userSettingsDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: User settings directory path must be rooted.");
                        return(false);
                    }
                    //if( !Directory.Exists( userSettingsDirectory ) )
                    //	Log.Fatal( "VirtualFileSystem: Init: Specified User settijngs directory is not exists." );
                    userSettingsDirectory    = VirtualPathUtility.NormalizePath(userSettingsDirectory);
                    Directories.userSettings = userSettingsDirectory;

                    if (!string.IsNullOrEmpty(overrideBinariesDirectory) && !Directory.Exists(overrideBinariesDirectory))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Specified binaries directory is not exists.");
                    }
                    if (string.IsNullOrEmpty(overrideBinariesDirectory))
                    {
                        Directories.binaries = PlatformSpecificUtility.Instance.GetExecutableDirectoryPath();
                    }
                    else
                    {
                        Directories.binaries = overrideBinariesDirectory;
                    }
                    Directories.binaries = VirtualPathUtility.NormalizePath(Directories.binaries);
                    if (!Path.IsPathRooted(Directories.binaries))
                    {
                        Log.Fatal("VirtualFileSystem: Init: Executables directory path must be rooted.");
                        return(false);
                    }

                    //// UWP works with relative paths.
                    // should Directories.engineInternal and Directories.platformSpecific be relative for UWP ?
                    //if( SystemSettings.CurrentPlatform == SystemSettings.Platform.UWP )
                    //	Directories.engineInternal = "NeoAxis.Internal";
                    //else
                    Directories.engineInternal = Path.Combine(Directories.binaries, "NeoAxis.Internal");

                    Directories.platformSpecific = Path.Combine(Directories.engineInternal, Path.Combine("Platforms", SystemSettings.CurrentPlatform.ToString()));

                    //!!!!
                    //!!!!ARM
                    if (SystemSettings.CurrentPlatform == SystemSettings.Platform.UWP)
                    {
                        Directories.platformSpecific = Path.Combine(Directories.platformSpecific, "x64");
                    }
                }

                //!!!!new
                CultureInfo.CurrentCulture = new CultureInfo("en-US");
                try
                {
                    //!!!! deprecated. use CultureInfo.CurrentCulture https://github.com/dotnet/platform-compat/blob/master/docs/DE0008.md
                    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                }
                catch { }

                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                //bool monoRuntime = Type.GetType( "Mono.Runtime", false ) != null;
                //if( monoRuntime )
                //	AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

                if (setCurrentDirectory)
                {
                    CorrectCurrentDirectory();
                }

                if (EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Editor)
                {
                    Editor.PackageManager.DeleteFilesAsStartup();
                }

                NativeLibraryManager.PreLoadLibrary("NeoAxisCoreNative");

                InitDefaultSettingsConfig();

                ArchiveManager.Init();
                //if( !ArchiveManager.Init() )
                //{
                //	//ArchiveManager.Shutdown();
                //	return false;
                //}

                initialized = true;

                //InitDeploymentInfoAndUserDirectory();

                string realPath = null;
                if (!string.IsNullOrEmpty(logFileName))
                {
                    realPath = VirtualPathUtility.GetRealPathByVirtual(logFileName);
                }
                Log.Init(Thread.CurrentThread, realPath);

                //!!!!
                //InitFileTypesThatCanBeCached();

                ResourceManager.Init();
                //RegisterAssemblies_IncludingFromDefaultSettingConfig();
                ParseSettingsFromDefaultSettingsConfig();
                //ResourceTypes.Init();

                //!!!!тут?
                VirtualFileWatcher.Init();

                ResourceUpdate.Init();
            }
            finally
            {
                StartupTiming.CounterEnd("Initialize virtual file system");
            }

            return(true);
        }
Example #3
0
        public static VirtualFileStream Open(string path)
        {
            if (!VirtualFileSystem.initialized)
            {
                Log.Fatal("VirtualFileSystem: File system is not initialized.");
            }

            if (VirtualFileSystem.LoggingFileOperations)
            {
                Log.Info("Logging file operations: VirtualFile.Open( \"{0}\" )", path);
            }

            path = VirtualPathUtility.NormalizePath(path);

            string realPath = VirtualPathUtility.GetRealPathByVirtual(path);

            if (File.Exists(realPath))
            {
                VirtualFileStream stream = null;
                {
                    //!!!!!
                    //try
                    //{

                    if (SystemSettings.CurrentPlatform == SystemSettings.Platform.Windows)
                    {
                        stream = new Win32HandleVirtualFileStream(realPath);
                    }
                    else if (SystemSettings.CurrentPlatform == SystemSettings.Platform.MacOS)
                    {
                        stream = new MacOSXVirtualFileStream(realPath);
                    }
                    else
                    {
                        stream = new DefaultVirtualFileStream(realPath);
                    }

                    //!!!!
                    //}
                    //catch( FileNotFoundException )
                    //{
                    //}
                    //catch( Exception e )
                    //{
                    //	throw e;
                    //}

                    //if( stream == null )
                    //{
                    //	stream = PackageManager.FileOpen( path );
                    //	if( stream == null )
                    //		throw new FileNotFoundException( "File not found.", path );
                    //}
                }

                return(stream);
            }

            {
                (var fileExists, var stream) = ArchiveManager.FileOpen(path);
                if (fileExists)
                {
                    return(stream);
                }
            }
            //if( ArchiveManager.FileExists( path ) )
            //	return ArchiveManager.FileOpen( path );

            throw new FileNotFoundException("File not found.", path);

            //!!!!всё закомменченное

            //lock ( VirtualFileSystem.lockObject )
            //{

            //	path = VirtualFileSystem.GetRedirectedFileNameInternal( path, true );

            //	bool canBeCached = VirtualFileSystem.IsFileCanBeCached( path );

            //	//get from cache
            //	if( canBeCached )
            //	{
            //		byte[] data = VirtualFileSystem.GetVirtualFileDataFromCache( path );
            //		if( data != null )
            //			return new MemoryVirtualFileStream( data );
            //	}

            //	//preloaded files to memory
            //	if( VirtualFileSystem.preloadedFilesToMemory.Count != 0 )
            //	{
            //		string pathLowerCase = path.ToLower();
            //		VirtualFileSystem.PreloadFileToMemoryItem item;
            //		if( VirtualFileSystem.preloadedFilesToMemory.TryGetValue( pathLowerCase, out item ) )
            //		{
            //			if( item.loaded )
            //				return new MemoryVirtualFileStream( item.data );
            //		}
            //	}

            //	VirtualFileStream stream = null;
            //	{
            //		string realPath = VirtualPathUtils.GetRealPathByVirtual( path );

            //		try
            //		{
            //			if( SystemSettings.CurrentPlatform == SystemSettings.Platform.Windows )
            //				stream = new Win32HandleVirtualFileStream( realPath );
            //			else if( SystemSettings.CurrentPlatform == SystemSettings.Platform.MacOS )
            //				stream = new MacOSXVirtualFileStream( realPath );
            //			else
            //				stream = new DefaultVirtualFileStream( realPath );
            //		}
            //		catch( FileNotFoundException )
            //		{
            //		}
            //		catch( Exception e )
            //		{
            //			throw e;
            //		}

            //		if( stream == null )
            //		{
            //			stream = PackageManager.FileOpen( path );
            //			if( stream == null )
            //				throw new FileNotFoundException( "File not found.", path );
            //		}

            //		//if( File.Exists( realPath ) )
            //		//{
            //		//   if( PlatformInfo.Platform == PlatformInfo.Platforms.Windows )
            //		//      stream = new Win32HandleVirtualFileStream( realPath );
            //		//   else if( PlatformInfo.Platform == PlatformInfo.Platforms.MacOSX )
            //		//      stream = new MacOSXVirtualFileStream( realPath );
            //		//   else
            //		//      stream = new DefaultVirtualFileStream( realPath );
            //		//}
            //		//else
            //		//{
            //		//   stream = ArchiveManager.Instance.FileOpen( path );
            //		//   if( stream == null )
            //		//      throw new FileNotFoundException();
            //		//}
            //	}

            //	//put to cache
            //	if( canBeCached )
            //	{
            //		byte[] data = new byte[ stream.Length ];
            //		if( stream.Read( data, 0, (int)stream.Length ) == stream.Length )
            //			VirtualFileSystem.AddVirtualFileToCache( path, data );
            //		stream.Position = 0;
            //	}

            //	//{
            //	//   byte[] buffer = new byte[ stream.Length ];
            //	//   stream.Read( buffer, 0, (int)stream.Length );
            //	//   stream.Close();

            //	//   MemoryVirtualFileStream memoryStream = new MemoryVirtualFileStream( buffer );
            //	//   return memoryStream;
            //	//}

            //	return stream;
            //}
        }