Beispiel #1
0
        public bool open(String szFilePath, EOpenModes eMode)
        {
            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                szFilePath = CFilePath.removeFirstSlash(szFilePath);
                if (eMode == EOpenModes.OpenForAppend || eMode == EOpenModes.OpenForReadWrite)
                {
                    if (!isFileExist(szFilePath))
                    {
                        m_st = isoStore.OpenFile(szFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
                    }

                    if (eMode == EOpenModes.OpenForAppend)
                    {
                        movePosToEnd();
                    }
                }
                else if (eMode == EOpenModes.OpenReadOnly)
                {
                    m_st = isoStore.OpenFile(szFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
                else if (eMode == EOpenModes.OpenForWrite)
                {
                    m_st = isoStore.OpenFile(szFilePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
                }
            }

            return(isOpened());
        }
Beispiel #2
0
        public static byte[] readResourceFile(String path)
        {
            byte[] content = new byte[0];
            path = CFilePath.removeFirstSlash(path);

            if (!CRhoFile.isResourceFileExist(path))
            {
                return(content);
            }

            var task = StorageFile.GetFileFromApplicationUriAsync(new Uri(path, UriKind.Relative)).AsTask();

            task.Wait();
            var sr         = task.Result;
            var streamTask = sr.OpenStreamForReadAsync();

            streamTask.Wait();

            using (System.IO.BinaryReader br = new BinaryReader(streamTask.Result))
            {
                content = br.ReadBytes((int)streamTask.Result.Length);
            }

            return(content);
        }
Beispiel #3
0
        public static bool isResourceFileExist(String path)
        {
            StreamResourceInfo sr = Application.GetResourceStream(new Uri(CFilePath.removeFirstSlash(path), UriKind.Relative));

            if (sr == null)
            {
                return(false);
            }

            return(sr != null);
        }
Beispiel #4
0
        public static byte[] readResourceFile(String path)
        {
            byte[] content = new byte[0];
            path = CFilePath.removeFirstSlash(path);

            if (!CRhoFile.isResourceFileExist(path))
            {
                return(content);
            }

            StreamResourceInfo sr = Application.GetResourceStream(new Uri(path, UriKind.Relative));

            using (System.IO.BinaryReader br = new BinaryReader(sr.Stream))
            {
                content = br.ReadBytes((int)sr.Stream.Length);
            }

            return(content);
        }
Beispiel #5
0
        public static String readFileToString(String path)
        {
            string content = "";

            path = CFilePath.removeFirstSlash(path);

            if (!isFileExist(path))
            {
                return(content);
            }

            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                using (Stream st = isoStore.OpenFile(path, FileMode.Open, FileAccess.Read, FileShare.None))
                    using (System.IO.BinaryReader br = new BinaryReader(st))
                    {
                        content = new String(br.ReadChars((int)st.Length));
                    }
            return(content);
        }
Beispiel #6
0
        public static String readStringFromResourceFile(String path)
        {
            string content = "";

            path = CFilePath.removeFirstSlash(path);

            if (!CRhoFile.isResourceFileExist(path))
            {
                return(content);
            }

            StreamResourceInfo sr = Application.GetResourceStream(new Uri(path, UriKind.Relative));

            using (System.IO.BinaryReader br = new BinaryReader(sr.Stream))
            {
                char[] str = br.ReadChars((int)sr.Stream.Length);
                content = new string(str);
            }

            return(content);
        }