Пример #1
0
        public override Uri MapUri(Uri uri)
        {
            this.tempUri = uri.ToString();

            if (tempUri.Contains("/FileTypeAssociation"))
            {
                int    fileIdIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIdIndex);

                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                string incomingFileType = Path.GetExtension(incomingFileName);

                switch (incomingFileType)
                {
                case ".smc":
                case ".sfc":
                    return(new Uri("/MainPage.xaml?fileToken=" + fileID, UriKind.Relative));

                default:
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }

            return(uri);
        }
Пример #2
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            // File association launch
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
                string incomingFileType = Path.GetExtension(incomingFileName).ToLower();

                switch (incomingFileType)
                {
                case ".kdbx":
                    return(new Uri("/Sources/Download.xaml?folder=&fileToken=" + fileID, UriKind.Relative));

                default:
                    // Otherwise perform normal launch.
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }
            return(uri);
        }
Пример #3
0
        protected async override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled)
            {
                return;
            }
            InitialLocalValues();
            if (NavigationContext.QueryString.ContainsKey("fileToken") && !e.IsNavigationInitiator)
            {
                string fileID           = NavigationContext.QueryString["fileToken"];
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                string msg = Strings.Download_OpenConfirm + incomingFileName + "'";
                if (MessageBox.Show(msg, Strings.Download_OpenDB, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    await loadExternalFile(fileID, _type);
                }
            }

            var app = App.Current as App;

            if (app.QueueFileOpenPickerArgs.Count != 0)
            {
                this.ContinueFileOpenPicker(app.QueueFileOpenPickerArgs.Dequeue());
            }
        }
Пример #4
0
        public override Uri MapUri(Uri uri)
        {
            this.tempUri = uri.ToString();

            if (tempUri.Contains("/FileTypeAssociation"))
            {
                int    fileIdIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIdIndex);

                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                string incomingFileType = Path.GetExtension(incomingFileName).ToLower();

                if (incomingFileType.Contains("cloudsix")) //this is from cloudsix, need to get the true file name and file type
                {
                    CloudSixFileSelected fileinfo = CloudSixPicker.GetAnswer(fileID);
                    incomingFileName = fileinfo.Filename;
                    incomingFileType = Path.GetExtension(incomingFileName).ToLower();
                }


                if (incomingFileType == ".gb" || incomingFileType == ".gbc" || incomingFileType == ".gba" || incomingFileType == ".sav" ||
                    incomingFileType == ".sgm" || incomingFileType == ".zip" || incomingFileType == ".zib" || incomingFileType == ".rar" ||
                    incomingFileType == ".7z")
                {
                    return(new Uri("/MainPage.xaml?fileToken=" + fileID, UriKind.Relative));
                }
                else
                {
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }

            return(uri);
        }
Пример #5
0
        private async Task loadExternalFile(string fileID, string type)
        {
            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                isoStore.CreateDirectory("temp");
            }
            StorageFolder tempFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFolderAsync("temp");

            // Get the file name.
            string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
            var    file             = await SharedStorageAccessManager.CopySharedFileAsync(tempFolder, incomingFileName, NameCollisionOption.ReplaceExisting, fileID);

            var info             = new DatabaseInfo();
            var randAccessStream = await file.OpenReadAsync();

            if (type.ToLower() == ".kdbx")
            {
                info.SetDatabase(randAccessStream.AsStream(), new DatabaseDetails
                {
                    Source = "ExternalApp",
                    Name   = incomingFileName.RemoveKdbx(),
                    Type   = SourceTypes.OneTime,
                });
            }

            this.NavigateTo <MainPage>();
        }
Пример #6
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            // File association launch
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
                var extension = Path.GetExtension(incomingFileName);
                if (extension != null)
                {
                    string incomingFileType = extension.ToLower();

                    if (".key" == incomingFileType || incomingFileType == ".kdbx")
                    {
                        return(new Uri($"/Sources/Download.xaml?type={incomingFileType}&folder=&fileToken={fileID}", UriKind.Relative));
                    }
                }
                return(new Uri("/MainPage.xaml", UriKind.Relative));
            }
            return(uri);
        }
Пример #7
0
    public override Uri MapUri(Uri uri)
    {
        strUri = uri.ToString();

        // File association launch
        if (strUri.Contains("/FileTypeAssociation"))
        {
            // Get the file ID (after "fileToken=").
            int    nFileIDIndex = strUri.IndexOf("fileToken=") + 10;
            string strFileID    = strUri.Substring(nFileIDIndex);

            string strFileName         = SharedStorageAccessManager.GetSharedFileName(strFileID);
            string strIncomingFileType = Path.GetExtension(strFileName);

            string strData = fnCopyToLocalFolderAndReadContents(strFileID).Result;

            switch (fileType)
            {
            case ".gmm":
                //determine if gmm is text
                if (objGMM.fnGetGMMType() == GMMFILETYPE.TXT)
                {
                    return(new Uri("/PageReadText.xaml?data=" + strData, UriKind.Relative));
                }
                break;
            }
        }
    }
Пример #8
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();
            // 根据文件类型打开程序
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // 获取fileID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIDIndex);
                // 获取文件名.
                string incommingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                // 获取文件后缀
                int    extensionIndex    = incommingFileName.LastIndexOf('.') + 1;
                string incommingFileType = incommingFileName.Substring(extensionIndex).ToLower();
                // 根据不同文件类型,跳转不同参数的地址
                switch (incommingFileType)
                {
                case "wx23c4db6d0d03d3f9":
                    return(new Uri("/Page/WeixinPage.xaml?fileToken=" + fileID, UriKind.Relative));

                default:
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }
            else
            {
                return(uri);
            }
        }
Пример #9
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName =
                    SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
                string incomingFileType = Path.GetExtension(incomingFileName);

                if (incomingFileType.Contains(".gpx"))
                {
                    return(new Uri("/ViewRoute.xaml?fileToken=" + fileID, UriKind.Relative));
                }
                else
                {
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }
            // Otherwise perform normal launch.
            return(uri);
        }
Пример #10
0
    public override Uri MapUri(Uri uri)
    {
        string uriStr = uri.ToString();

        if (uriStr.Contains("/FileTypeAssociation"))
        {
            int    fileIDIndex       = uriStr.IndexOf("fileToken=") + 10;
            string fileID            = uriStr.Substring(fileIDIndex);
            string incommingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

            // Path.GetExtension will return String.Empty if no file extension found.
            int    extensionIndex   = incommingFileName.LastIndexOf('.') + 1;
            string incomingFileType = incommingFileName.Substring(extensionIndex).ToLower();

            if (incomingFileType == WeChat.appId)
            {
                return(new Uri("/WeChatCallbackPage.xaml?fileToken=" + fileID, UriKind.Relative));
            }
        }

        if (upper != null)
        {
            var upperResult = upper.MapUri(uri);

            if (upperResult != uri)
            {
                return(upperResult);
            }
        }

        return(new Uri("/MainPage.xaml", UriKind.Relative));
    }
Пример #11
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            //get the fileID
            try
            {
                String fileID = NavigationContext.QueryString["fileToken"];
                NavigationContext.QueryString.Remove("fileToken");

                //currently only zip file need to use this page, copy the zip file to local storage
                StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                string        fileName    = SharedStorageAccessManager.GetSharedFileName(fileID);
                tempZipFile = await SharedStorageAccessManager.CopySharedFileAsync(localFolder, fileName, NameCollisionOption.ReplaceExisting, fileID);

                //set the title
                CloudSixFileSelected fileinfo = CloudSixPicker.GetAnswer(fileID);
                currentFolderBox.Text = fileinfo.Filename;
                string ext = Path.GetExtension(fileinfo.Filename).ToLower();

                //open zip file or rar file
                try
                {
                    SkyDriveItemType type = SkyDriveItemType.File;
                    if (ext == ".zip" || ext == ".zib")
                    {
                        type = SkyDriveItemType.Zip;
                    }
                    else if (ext == ".rar")
                    {
                        type = SkyDriveItemType.Rar;
                    }
                    else if (ext == ".7z")
                    {
                        type = SkyDriveItemType.SevenZip;
                    }

                    skydriveStack = await GetFilesInArchive(type, tempZipFile);

                    this.skydriveList.ItemsSource = skydriveStack;

                    var indicator = SystemTray.GetProgressIndicator(this);
                    indicator.IsIndeterminate = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, AppResources.ErrorCaption, MessageBoxButton.OK);
                }
            }
            catch (Exception)
            {
                MessageBox.Show(AppResources.FileAssociationError, AppResources.ErrorCaption, MessageBoxButton.OK);
            }



            base.OnNavigatedTo(e);
        }
Пример #12
0
        private async Task SaveFileToStorageAsync()
        {
            string fileToken = NavigationContext.QueryString["fileToken"];
            string fileName  = SharedStorageAccessManager.GetSharedFileName(fileToken);

            _storedFile = await SharedStorageAccessManager
                          .CopySharedFileAsync(_filesFolder,
                                               fileName,
                                               NameCollisionOption.ReplaceExisting,
                                               fileToken);
        }
Пример #13
0
        public override Uri MapUri(Uri uri)
        {
            var navigationService = IoC.Get <INavigationService>();
            var catalogRepository = IoC.Get <ICatalogRepository>();

            string tempUri = uri.ToString();

            // File association launch
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=", StringComparison.InvariantCulture) + 10;
                string fileID      = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
// ReSharper disable PossibleNullReferenceException
                string incomingFileType = Path.GetExtension(incomingFileName).ToLower();
// ReSharper restore PossibleNullReferenceException


                var catalog = catalogRepository.GetAll().Single(c => c.Type == CatalogType.StorageFolder);

                var bookItemModel = new CatalogBookItemModel
                {
                    Title       = Path.GetFileNameWithoutExtension(incomingFileName),
                    Description = string.Empty,
                    Author      = string.Empty,
                    Links       = new List <BookDownloadLinkModel>
                    {
                        new BookDownloadLinkModel {
                            Type = incomingFileType, Url = fileID
                        }
                    },
                    Id = fileID
                };

                return(navigationService
                       .UriFor <BookInfoPageViewModel>()
                       .WithParam(vm => vm.Title, bookItemModel.Title.ToUpper())
                       .WithParam(vm => vm.Description, bookItemModel.Description)
                       .WithParam(vm => vm.CatalogId, catalog.Id)
                       .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(bookItemModel))
                       .BuildUri());
            }
            // Otherwise perform normal launch.
            return(uri);
        }
Пример #14
0
        static public async void importGCodeFile(string fileToken)
        {
            //Check if the stl folder exists
            //if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\GCode"))
            //  Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\GCode");

            try
            {
                //Create the target folder
                StorageFolder targetFolder = ApplicationData.Current.LocalFolder;

                // Get the full file name of the route (.GPX file) from the file association.
                string incomingRouteFilename = SharedStorageAccessManager.GetSharedFileName(fileToken);

                //Change the extension to lower case ".gcode" as to avoid confusion
                incomingRouteFilename = Path.ChangeExtension(incomingRouteFilename, ".gcode");

                // Copy the route (.GPX file) to the Routes folder.
                IStorageFile routeFile = await SharedStorageAccessManager.CopySharedFileAsync(targetFolder, incomingRouteFilename, NameCollisionOption.ReplaceExisting, fileToken);

                //Set the starting GCode file
                Values.currentGCodeFile = incomingRouteFilename;

                //Tell the mainpage to open on the gcode pivot
                Values.startFileType = "gcode";

                Values.GCode_Items = FileFinder.findFilesAndCreateList("GCode", ".gcode");

                //Determine the index of the gcode file and assign it
                for (int i = 0; i < Values.GCode_Items.Count; i++)
                {
                    if (Values.GCode_Items[i].FilePath == Values.currentGCodeFile)
                    {
                        Values.GCode_ListIndex = i;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                /*App.RootFrame.Dispatcher.BeginInvoke(() =>
                 * {
                 *  MessageBox.Show(e.ToString());
                 * });*/
            }
        }
Пример #15
0
        /// <summary>
        /// Copies a file into local folder from shared storage.
        /// </summary>
        /// <returns>fileName</returns>
        public async Task <string> SharedStorageCopyFile(string fileToken)
        {
            string        fileName;
            MiscFunctions misc = new MiscFunctions();

            try
            {
                fileName = SharedStorageAccessManager.GetSharedFileName(fileToken);

                await SharedStorageAccessManager.CopySharedFileAsync(Windows.Storage.ApplicationData.Current.LocalFolder, fileName, Windows.Storage.NameCollisionOption.ReplaceExisting, fileToken);

                return(fileName);
            }
            catch
            {
                return(null);
            }
        }
Пример #16
0
        public override Uri MapUri(Uri uri)
        {
            var uriString = uri.ToString();

            if (uriString.Contains("/FileTypeAssociation"))
            {
                string fileToken = uriString.GetFileToken();
                string fileName  = SharedStorageAccessManager
                                   .GetSharedFileName(fileToken);

                if (!String.IsNullOrEmpty(fileName) &&
                    fileName.Extension().Equals(".city"))
                {
                    return(new Uri("/CityPage.xaml?fileToken=" + fileToken, UriKind.Relative));
                }
            }

            return(uri);
        }
Пример #17
0
        protected async override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            string UniqueId = "";

            if (NavigationContext.QueryString.ContainsKey("Command"))
            {
                string fileToken = NavigationContext.QueryString["ID"];
                var    filename  = SharedStorageAccessManager.GetSharedFileName(fileToken);

                var file = await SharedStorageAccessManager.CopySharedFileAsync(Windows.Storage.ApplicationData.Current.LocalFolder,
                                                                                fileToken + ".rcp", Windows.Storage.NameCollisionOption.ReplaceExisting,
                                                                                fileToken);

                var content = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                DataReader dr = new DataReader(content);
                await dr.LoadAsync((uint)content.Size);

                //Get XML from file content
                string xml = dr.ReadString((uint)content.Size);

                //Load XML dpocument
                XDocument  doc     = XDocument.Parse(xml);
                XName      attName = XName.Get("ID");
                XAttribute att     = doc.Root.Attribute(attName);
                //Get UniqueId from file
                UniqueId = att.Value;
                System.Diagnostics.Debug.WriteLine("ID = " + UniqueId);
            }
            else
            {
                UniqueId = NavigationContext.QueryString["ID"];
            }

            if (!App.Recipes.IsLoaded)
            {
                await App.Recipes.LoadLocalDataAsync();
            }

            NavigateToRecipe(UniqueId);

            base.OnNavigatedTo(e);
        }
Пример #18
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            // Protocol association launch for contoso.
            if (tempUri.Contains("uve"))
            {
                return(new Uri("/System/Launch.xaml?LAUNCHURI=" + tempUri, UriKind.Relative));
            }
            else if (tempUri.Contains("/FileTypeAssociation"))
            {
                int    fileIDIndex      = tempUri.IndexOf("fileToken=") + 10;
                string fileID           = tempUri.Substring(fileIDIndex);
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                string incomingFileType = System.IO.Path.GetExtension(incomingFileName);
                return(new Uri("/System/OpenFile.xaml?fileToken=" + fileID + "&fileType=" + incomingFileType, UriKind.Relative));
            }

            // Include the original URI with the mapping to the main page.
            return(uri);
        }
Пример #19
0
        internal static async Task <ROMDBEntry> ImportRomBySharedID(string importRomID)
        {
            ROMDatabase db       = ROMDatabase.Current;
            string      filename = SharedStorageAccessManager.GetSharedFileName(importRomID);

            ROMDBEntry entry = db.GetROM(filename);

            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFolder romFolder   = await localFolder.GetFolderAsync(ROM_DIRECTORY);

            IStorageFile file = await SharedStorageAccessManager.CopySharedFileAsync(romFolder, filename, NameCollisionOption.ReplaceExisting, importRomID);

            if (entry == null)
            {
                entry = FileHandler.InsertNewDBEntry(filename);
                await FileHandler.FindExistingSavestatesForNewROM(entry);

                db.CommitChanges();
            }

            return(entry);
        }
Пример #20
0
        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            // File association launch
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID      = tempUri.Substring(fileIDIndex);

                // Get the file name.
                string incomingFileName =
                    SharedStorageAccessManager.GetSharedFileName(fileID);

                // Get the file extension.
                string incomingFileType = Path.GetExtension(incomingFileName).ToLower();

                // Map the .sdkTest1 and .sdkTest2 files to different pages.
                switch (incomingFileType)
                {
                case ".gcode":
                    Values.startFileType = "gcode";
                    GCodeUriHandler.importGCodeFile(fileID);
                    return(new Uri("/MainPage.xaml?fileToken=" + fileID, UriKind.Relative));

                case ".stl":
                    Values.startFileType = "stl";
                    StlUriHandler.importStlFile(fileID);
                    return(new Uri("/MainPage.xaml?fileToken=" + fileID, UriKind.Relative));

                default:
                    return(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }
            // Otherwise perform normal launch.
            return(uri);
        }
Пример #21
0
            public override Uri MapUri(Uri uri)
            {
                string tempUri = uri.ToString();

                // File association launch
                if (tempUri.StartsWith("/FileTypeAssociation"))
                {
                    try
                    {
                        // Get the file ID (after "fileToken=").
                        int    fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                        string fileID      = tempUri.Substring(fileIDIndex);

                        // Get the file name.
                        string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

                        // Get the file extension.
                        string incomingFileType = System.IO.Path.GetExtension(incomingFileName);

                        // Map the recognized files to different pages.
                        switch (incomingFileType)
                        {
                        case ".gwc":
                            return(new Uri(String.Format("/Views/CartridgeInfoPage.xaml?{0}={1}", ViewModels.CartridgeInfoViewModel.FileTokenKey, fileID), UriKind.Relative));

                        default:
                            return(new Uri("/MainPage.xaml", UriKind.Relative));
                        }
                    }
                    catch (Exception)
                    {
                        return(uri);
                    }
                }

                // Otherwise perform normal launch.
                return(uri);
            }
Пример #22
0
        protected async override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled)
            {
                return;
            }

            lnkDemo.Visibility = Visibility.Collapsed;

            ApplicationBar.IsVisible = true;
            _folder = NavigationContext.QueryString["folder"];

            if (NavigationContext.QueryString.ContainsKey("fileToken") && !e.IsNavigationInitiator)
            {
                string fileID           = NavigationContext.QueryString["fileToken"];
                string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
                string msg = "Please confirm opening database file '" + incomingFileName + "'";
                if (MessageBox.Show(msg, "Open database file", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    await loadExternalFile(fileID);
                }
            }
        }
Пример #23
0
        async public void readfileToken(string fileToken)
        {
            // enables progress indicator
            //ProgressIndicator indicator = SystemTray.ProgressIndicator;
            //if (indicator != null)
            //{
            //    //indicator.Text = "载入文件中 ...";
            //    //indicator.IsVisible = true;
            //}

            try
            {
                // get file of the specific token
                // Create or open the routes folder.
                IStorageFolder routesFolder = ApplicationData.Current.LocalFolder;

                // Get the full file name of the route (.GPX file) from the file association.
                string incomingRouteFilename = SharedStorageAccessManager.GetSharedFileName(fileToken);

                //// purge all files from the Routes folder.
                //Debug.WriteLine("deleting all files within folder");
                //IEnumerable<StorageFile> files = await routesFolder.GetFilesAsync();

                //// Add each GPX file to the Routes collection.
                //foreach (StorageFile f in files)
                //{
                //    await f.DeleteAsync();
                //}

                // Copy the route (.GPX file) to the Routes folder.
                IStorageFile esf = await SharedStorageAccessManager.CopySharedFileAsync((StorageFolder)routesFolder, incomingRouteFilename, NameCollisionOption.ReplaceExisting, fileToken);

                if (esf != null)
                {
                    Debug.WriteLine("found file " + esf.Name);
                    if (esf.Path.EndsWith(".txtx"))
                    {
                        // print its content
                        var fileStream = await esf.OpenReadAsync();

                        Stream x      = fileStream.AsStream();
                        byte[] buffer = new byte[x.Length];
                        x.Read(buffer, 0, (int)x.Length);
                        x.Close();

                        string result = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                        //Debug.WriteLine(result);
                        //this.title.Text = "阅读器";
                        //Debug.WriteLine("title changed");
                        //this.content.Text = result.Substring(0, 10000);
                        //Debug.WriteLine("content changed");
                        this.contentString = result;

                        // cut content into pages
                        this.cutContentIntoPages();

                        // display first page
                        this.currentPage = 0;
                        this.displayCurrentPage();
                    }
                }
                Debug.WriteLine("done");
            }
            catch (FileNotFoundException)
            {
                // No Routes folder is present.
                this.content.Text = "Error loading file, reason: file not found";
                Debug.WriteLine("file not found.");
            }
        }
Пример #24
0
        /// <summary>
        /// Gets the single tag for a cartridge imported from a file association token.
        /// </summary>
        /// <param name="fileToken"></param>
        /// <returns>The single cartridge tag to match this token, or null if
        /// the cartridge could not be imported.</returns>
        public CartridgeTag GetCartridgeTagFromFileAssociation(string fileToken)
        {
            try
            {
                // Gets the source filename.
                string filename = SharedStorageAccessManager.GetSharedFileName(fileToken);
                if (System.IO.Path.GetExtension(filename) != ".gwc")
                {
                    return(null);
                }

                // Copies the file to isostore.
                SharedStorageAccessManager.CopySharedFileAsync(
                    ApplicationData.Current.LocalFolder,
                    filename,
                    NameCollisionOption.ReplaceExisting,
                    fileToken)
                .AsTask()
                .Wait();

                // Creates the target directory in the isostore.
                string filepath;
                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    // Gets the cartridge guid.
                    Cartridge cart = new Cartridge(filename);
                    using (IsolatedStorageFileStream isfs = isf.OpenFile(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    {
                        try
                        {
                            WF.Player.Core.Formats.CartridgeLoaders.LoadMetadata(isfs, cart);
                        }
                        catch (Exception ex)
                        {
                            // This cartridge seems improper to load.
                            // Let's just dump the exception and return.
                            DebugUtils.DumpException(ex, dumpOnBugSenseToo: true);
                            System.Diagnostics.Debug.WriteLine("CartridgeStore: WARNING: Loading failed, ignored : " + filename);
                            return(null);
                        }
                    }

                    // Sanity check.
                    if (String.IsNullOrWhiteSpace(cart.Guid))
                    {
                        return(null);
                    }

                    // Creates the folder for the file.
                    // Shared file tokens are not unique for each file, so we need the cartridge guid to distinguish unique
                    // files.
                    filepath = System.IO.Path.Combine(IsoStoreFileTypeAssociationCartridgesPath, cart.Guid, filename);
                    isf.CreateDirectory(System.IO.Path.GetDirectoryName(filepath));

                    // Moves the file to its destination.
                    // We overwrite because the cartridge GUID+filename should ensure unicity of the file.
                    isf.CopyFile(filename, filepath, true);
                    isf.DeleteFile(filename);
                }

                // Accepts the file.
                return(AcceptCartridge(filepath));
            }
            catch (Exception)
            {
                return(null);
            }
        }