示例#1
0
        public static System.IO.Stream OpenStream(string resName)
        {
            if (resName.IndexOf("/") == -1 && FileUtils.GetExtension(resName).Length == 0)
            {
                resName = "Assets/" + resName;
            }
            Stream resource = StrRes(resName);

            if (resource != null)
            {
                return(resource);
            }
            System.IO.Stream stream = null;
            try
            {
                stream = File.OpenRead(resName);
            }
            catch
            {
                try
                {
                    if (stream == null)
                    {
                        //      stream = XNAConfig.LoadStream(resName);
                    }
                }
                catch (Exception)
                {
                    if (stream == null)
                    {
                        Uri pathUri = new Uri("/" + JavaRuntime.GetAssemblyName() + ";component/" + resName, UriKind.RelativeOrAbsolute);
                        //    stream = ApplicationResourceStream(pathUri);
                    }
                }
            }
            if (stream == null)
            {
                try
                {
                    stream = new System.IO.FileStream(resName, System.IO.FileMode.Open);
                }
                catch
                {
                    try
                    {
                        //   System.IO.IsolatedStorage.IsolatedStorageFile store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
                        //  stream = store.OpenFile(resName, System.IO.FileMode.Open);
                    }
                    catch (Exception ex)
                    {
                        Loon.Utils.Debug.Log.Exception(ex);
                        Loon.Utils.Debug.Log.DebugWrite("\n" + resName + " file not found !");
                    }
                }
            }
            return(stream);
        }
示例#2
0
        /// <summary>
        /// 尝试读取数据流
        /// </summary>
        /// <param name="resName"></param>
        /// <returns></returns>
        public static System.IO.Stream OpenStream(string @resName)
        {
            Stream resource = StrRes(resName);

            if (resource != null)
            {
                return(resource);
            }
            //尝试读取XAP中文件(Content类型)
            System.IO.Stream stream = null;
            try
            {
                stream = TitleContainer.OpenStream(resName);
            }
            catch
            {
                if (stream == null)
                {
                    //尝试读取DLL中文件(Resource类型)
                    Uri pathUri = new Uri("/" + JavaRuntime.GetAssemblyName() + ";component/" + resName, UriKind.RelativeOrAbsolute);
                    stream = ApplicationResourceStream(pathUri);
                }
            }
            if (stream == null)
            {
                //尝试读取标准路径数据
                try
                {
                    stream = new System.IO.FileStream(resName, System.IO.FileMode.Open);
                }
                catch
                {
                    //尝试读取封闭空间中数据
                    try
                    {
                        System.IO.IsolatedStorage.IsolatedStorageFile store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
                        stream = store.OpenFile(resName, System.IO.FileMode.Open);
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        Log.DebugWrite("\n" + resName + " file not found !");
                    }
                }
            }
            return(stream);
        }
示例#3
0
        /// <summary>
        /// 尝试读取数据流
        /// </summary>
        /// <param name="resName"></param>
        /// <returns></returns>
        public static System.IO.Stream OpenStream(string resName)
        {
            if (resName.IndexOf("/") == -1 && FileUtils.GetExtension(resName).Length == 0)
            {
                resName = "Content/" + resName;
            }
            Stream resource = StrRes(resName);

            if (resource != null)
            {
                return(resource);
            }
            //尝试读取XAP中文件(Content类型)
            System.IO.Stream stream = null;
            try
            {
                stream = TitleContainer.OpenStream(resName);
            }
            catch
            {
                try
                {
                    if (stream == null)
                    {
                        stream = XNAConfig.LoadStream(resName);
                    }
                }
                catch (Exception)
                {
                    if (stream == null)
                    {
                        //尝试读取DLL中文件(Resource类型)
                        Uri pathUri = new Uri("/" + JavaRuntime.GetAssemblyName() + ";component/" + resName, UriKind.RelativeOrAbsolute);
                        stream = ApplicationResourceStream(pathUri);
                    }
                }
            }
            if (stream == null)
            {
                //尝试读取标准路径数据
                try
                {
                    stream = new System.IO.FileStream(resName, System.IO.FileMode.Open);
                }
                catch
                {
                    //尝试读取封闭空间中数据
                    try
                    {
                        System.IO.IsolatedStorage.IsolatedStorageFile store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
                        stream = store.OpenFile(resName, System.IO.FileMode.Open);
                    }
                    catch (Exception ex)
                    {
                        Loon.Utils.Debugging.Log.Exception(ex);
                        Loon.Utils.Debugging.Log.DebugWrite('\n' + resName + " file not found !");
                    }
                }
            }
            return(stream);
        }