Ejemplo n.º 1
0
        private void init(string filename, Stream stream, Loader.LoadedCallbackMethod loadedCallback)
                #endif
        {
            try
            {
                if (filename != null)
                {
                    fromFile = true;
                                        #if WINRT || WP8
                    LoadedStream = await Streams.OpenFile(filename);
                                        #elif NaCl
                    this.loadedCallback = loadedCallback;

                    filename = filename.Replace('\\', '/');
                    file     = new NaClFile(filename);
                    Streams.NaClFileLoadedCallback += fileLoaded;
                    Streams.addPendingFile(file);
                    Loader.AddLoadable(this);

                    return;
                                        #else
                    LoadedStream = Streams.OpenFile(filename);
                                        #endif
                }
                else
                {
                    fromFile     = false;
                    LoadedStream = stream;
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
        }
Ejemplo n.º 2
0
        private void fileLoaded(NaClFile file)
        {
            if (file.ID == this.file.ID)
            {
                Streams.NaClFileLoadedCallback -= fileLoaded;

                if (file.FailedToLoad)
                {
                    FailedToLoad = true;
                    if (loadedCallback != null)
                    {
                        loadedCallback(this, false);
                    }
                    loadedCallback = null;
                    Dispose();
                    return;
                }

                try
                {
                    LoadedStream          = new MemoryStream(file.Data);
                    LoadedStream.Position = 0;
                }
                catch (Exception e)
                {
                    FailedToLoad = true;
                    Loader.AddLoadableException(e);
                    if (loadedCallback != null)
                    {
                        loadedCallback(this, false);
                    }
                    loadedCallback = null;
                    Dispose();
                    return;
                }

                Loaded = true;
                if (loadedCallback != null)
                {
                    loadedCallback(this, true);
                }
                loadedCallback = null;
            }
        }
Ejemplo n.º 3
0
 internal static void addPendingFile(NaClFile file)
 {
     naclFiles.Add(file);
     URLLoader_LoadFile(file.FileName, file.ID.ToString());
 }
Ejemplo n.º 4
0
		private void init(string filename, Stream stream, Loader.LoadedCallbackMethod loadedCallback)
		#endif
		{
			try
			{
				if (filename != null)
				{
					fromFile = true;
					#if WINRT || WP8
					LoadedStream = await Streams.OpenFile(filename);
					#elif NaCl
					this.loadedCallback = loadedCallback;
					
					filename = filename.Replace('\\', '/');
					file = new NaClFile(filename);
					Streams.NaClFileLoadedCallback += fileLoaded;
					Streams.addPendingFile(file);
					Loader.AddLoadable(this);
					
					return;
					#else
					LoadedStream = Streams.OpenFile(filename);
					#endif
				}
				else
				{
					fromFile = false;
					LoadedStream = stream;
				}
			}
			catch (Exception e)
			{
				FailedToLoad = true;
				Loader.AddLoadableException(e);
				Dispose();
				if (loadedCallback != null) loadedCallback(this, false);
				return;
			}

			Loaded = true;
			if (loadedCallback != null) loadedCallback(this, true);
		}
Ejemplo n.º 5
0
		internal static void addPendingFile(NaClFile file)
		{
			naclFiles.Add(file);
			URLLoader_LoadFile(file.FileName, file.ID.ToString());
		}
Ejemplo n.º 6
0
		private void fileLoaded(NaClFile file)
		{
			if (file.ID == this.file.ID)
			{
				Streams.NaClFileLoadedCallback -= fileLoaded;
				
				if (file.FailedToLoad)
				{
					FailedToLoad = true;
					if (loadedCallback != null) loadedCallback(this, false);
					loadedCallback = null;
					Dispose();
					return;
				}
				
				try
				{
					LoadedStream = new MemoryStream(file.Data);
					LoadedStream.Position = 0;
				}
				catch (Exception e)
				{
					FailedToLoad = true;
					Loader.AddLoadableException(e);
					if (loadedCallback != null) loadedCallback(this, false);
					loadedCallback = null;
					Dispose();
					return;
				}
				
				Loaded = true;
				if (loadedCallback != null) loadedCallback(this, true);
				loadedCallback = null;
			}
		}