unsafe static void skip(void */*MyOgreVirtualDataStream*/ stream, int count)
        {
            //BeginCounter();

            VirtualFileStream s = GetStreamByOgreStream(stream);

            s.Seek(count, SeekOrigin.Current);

            //EndCounter();
        }
        unsafe static void seek(void */*MyOgreVirtualDataStream*/ stream, int pos)
        {
            //BeginCounter();

            VirtualFileStream s = GetStreamByOgreStream(stream);

            s.Seek(pos, SeekOrigin.Begin);

            //EndCounter();
        }
        unsafe static int tell(void */*MyOgreVirtualDataStream*/ stream)
        {
            //BeginCounter();
            //VirtualFileStream s = GetStreamByOgreStream( stream );
            //int result = (int)s.Position;
            //EndCounter();
            //return result;

            VirtualFileStream s = GetStreamByOgreStream(stream);

            return((int)s.Position);
        }
Exemple #4
0
        //!!!!
        //public static bool InsidePackage( string path )
        //{
        //	lock ( VirtualFileSystem.lockObject )
        //	{
        //		if( !VirtualFileSystem.initialized )
        //			Log.Fatal( "VirtualFileSystem: File system is not initialized." );

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

        //		path = VirtualPathUtils.NormalizePath( path );

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

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

        //		PackageManager.FileInfo fileInfo;
        //		return PackageManager.GetFileInfo( path, out fileInfo );
        //	}
        //}

        //!!!!!
        ////!!!!!!remove?
        //public static bool IsPackage( string path )
        //{
        //	lock ( VirtualFileSystem.lockObject )
        //	{
        //		if( VirtualFileSystem.LoggingFileOperations )
        //			Log.Info( "Logging file operations: VirtualFile.IsArchive( \"{0}\" )", path );

        //		path = VirtualPathUtils.NormalizePath( path );

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

        //		string realPath = VirtualPathUtils.GetRealPathByVirtual( path );
        //		return PackageManager.GetPackage( realPath ) != null;
        //	}
        //}

        public static byte[] ReadAllBytes(string path)
        {
            using (VirtualFileStream stream = Open(path))
            {
                byte[] result = new byte[stream.Length];
                if (stream.Read(result, 0, result.Length) != result.Length)
                {
                    throw new EndOfStreamException();
                }
                return(result);
            }
        }
        unsafe static VirtualFileStream GetStreamByOgreStream(void */*MyOgreVirtualDataStream*/ stream)
        {
            if (lastOpenedOgreStream == stream)
            {
                return(lastOpenedStream);
            }

            VirtualFileStream s = openedStreams[(IntPtr)stream];

            lastOpenedOgreStream = (MyOgreVirtualDataStream *)stream;
            lastOpenedStream     = s;
            return(s);
        }
        unsafe static int read(void */*MyOgreVirtualDataStream*/ stream, void *buf, int count)
        {
            //!!!!!right?
            EngineThreading.CheckMainThread();

            //BeginCounter();
            //VirtualFileStream s = GetStreamByOgreStream( stream );
            //int result = s.ReadUnmanaged( (IntPtr)buf, count );
            //EndCounter();
            //return result;

            VirtualFileStream s = GetStreamByOgreStream(stream);

            return(s.ReadUnmanaged((IntPtr)buf, count));
        }
        unsafe static void close(void */*MyOgreVirtualDataStream*/ stream)
        {
            VirtualFileStream s = GetStreamByOgreStream(stream);

            s.Dispose();

            bool removed = openedStreams.Remove((IntPtr)stream);

            Trace.Assert(removed);
            if (lastOpenedOgreStream == stream)
            {
                lastOpenedOgreStream = null;
                lastOpenedStream     = null;
            }

            //Log.Info( "totalTime: {0}, openings: {1}, calls: {2}", totalTime, openings, calls );
        }
        //static double totalTime;
        //static double startTime;
        //static int openings;
        //static int calls;

        //static void BeginCounter()
        //{
        //   //xx xx;
        //   startTime = RendererWorld.renderTimerManager.GetSystemTime();
        //   calls++;
        //}

        //static void EndCounter()
        //{
        //   double t = RendererWorld.renderTimerManager.GetSystemTime() - startTime;
        //   totalTime += t;
        //}

        unsafe static bool open(void */*MyOgreVirtualDataStream*/ stream, string fileName,
                                ref int streamSize, ref bool fileNotFound)
        {
            //!!!!!right?
            EngineThreading.CheckMainThread();

            //!!!!!посмотреть, что тут грузится. по сути не надо это ведь совсем. ну для шейдеров разве чтоли. тогда будет ли работать с мультипотоке?

            //openings++;
            //Log.Info( "OPEN: " + fileName );

            streamSize   = 0;
            fileNotFound = false;

            VirtualFileStream s;

            try
            {
                //watermark
                //if( fileName == WmImage.GetName() )
                //   s = WmImage.Open();
                //else
                s = VirtualFile.Open(fileName);
            }
            catch (FileNotFoundException)
            {
                fileNotFound = true;
                return(false);
            }
            catch
            {
                return(false);
            }
            streamSize = (int)s.Length;

            openedStreams.Add((IntPtr)stream, s);
            lastOpenedOgreStream = (MyOgreVirtualDataStream *)stream;
            lastOpenedStream     = s;

            return(true);
        }
Exemple #9
0
        void CreateOggFile()
        {
            PreloadNativeLibraries();

            DestroyOggFile();

            var fileName = FileName.Value?.ResourceName;

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }

            VirtualFileStream stream = null;

            try
            {
                stream = VirtualFile.Open(fileName);

                oggFile        = new OggFile();
                oggFile.Volume = Volume;

                bool sound3D = ParentContainer.Transform3D != null;                // is UIContainer3D;
                oggFile.Init(stream, new MyVideoDriver(videoBuffer), new MyAudioDriver(), sound3D);
            }
            catch (Exception ex)
            {
                if (!noLogErrorAtLoading)
                {
                    Log.Warning(string.Format("UIVideo: CreateOggFile: Error: {0} ({1}).", ex.Message, fileName));
                }

                if (oggFile != null)
                {
                    oggFile.Dispose();
                    oggFile = null;
                }

                if (stream != null)
                {
                    stream.Dispose();
                }

                return;
            }

            if (oggFile.VideoDriver == null)
            {
                oggFile.Dispose();
                oggFile = null;
            }

            if (oggFile == null)
            {
                return;
            }

            UpdateOggFileSoundPosition();

            oggFile.Pause = Pause;
        }
Exemple #10
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;
            //}
        }