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>(); }
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); }
async Task <string> fnCopyToLocalFolderAndReadContents(string strIncomingFileId) { StorageFolder objLocalFolder = Windows.Storage.ApplicationData.Current.LocalFolder; objFile = await SharedStorageAccessManager.CopySharedFileAsync(objLocalFolder, TEMP.gmm, NameCollisionOption.ReplaceExisting, strIncomingFileId); using (StreamReader streamReader = new StreamReader(objFile)) { return(streamReader.ReadToEnd()); } }
private async Task SaveFileToStorageAsync() { string fileToken = NavigationContext.QueryString["fileToken"]; string fileName = SharedStorageAccessManager.GetSharedFileName(fileToken); _storedFile = await SharedStorageAccessManager .CopySharedFileAsync(_filesFolder, fileName, NameCollisionOption.ReplaceExisting, fileToken); }
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()); * });*/ } }
//public static async Task RenameROMFile(string oldname, string newname) //{ // ROMDatabase db = ROMDatabase.Current; // StorageFolder localFolder = ApplicationData.Current.LocalFolder; // StorageFolder romFolder = await localFolder.GetFolderAsync(ROM_DIRECTORY); // StorageFile oldfile = await romFolder.GetFileAsync(oldname); // StorageFile newfile = await romFolder.CreateFileAsync(newname, CreationCollisionOption.ReplaceExisting); // using (var outputStream = await newfile.OpenStreamForWriteAsync()) // { // using (var inputStream = await oldfile.OpenStreamForReadAsync()) // { // await inputStream.CopyToAsync(outputStream); // } // } //} internal static async Task <ROMDBEntry> ImportRomBySharedID(string fileID, string desiredName, DependencyObject page) { //note: desiredName can be different from the file name obtained from fileID ROMDatabase db = ROMDatabase.Current; //set status bar var indicator = SystemTray.GetProgressIndicator(page); indicator.IsIndeterminate = true; indicator.Text = String.Format(AppResources.ImportingProgressText, desiredName); StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFolder romFolder = await localFolder.CreateFolderAsync(ROM_DIRECTORY, CreationCollisionOption.OpenIfExists); IStorageFile file = await SharedStorageAccessManager.CopySharedFileAsync(romFolder, desiredName, NameCollisionOption.ReplaceExisting, fileID); ROMDBEntry entry = db.GetROM(file.Name); if (entry == null) { entry = FileHandler.InsertNewDBEntry(file.Name); await FileHandler.FindExistingSavestatesForNewROM(entry); db.CommitChanges(); } //update voice command list await MainPage.UpdateGameListForVoiceCommand(); #if GBC indicator.Text = AppResources.ApplicationTitle2; #else indicator.Text = AppResources.ApplicationTitle; #endif indicator.IsIndeterminate = false; MessageBox.Show(String.Format(AppResources.ImportCompleteText, entry.DisplayName)); return(entry); }
/// <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); } }
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); }
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); }
private async void LoadFileAsync(string fileId, AsyncContext context) { try { var file = await SharedStorageAccessManager.CopySharedFileAsync(ApplicationData.Current.LocalFolder, fileId + ".tmp", NameCollisionOption.ReplaceExisting, fileId); using (var stream = await file.OpenStreamForReadAsync()) { context.Stream = CopyStream(stream); } await file.DeleteAsync(StorageDeleteOption.PermanentDelete); } catch (Exception exception) { context.Error = exception; } finally { context.WaitHandle.Set(); } }
internal static async Task ImportSaveBySharedID(string fileID, string actualName, DependencyObject page) { //note: the file name obtained from fileID can be different from actualName if the file is obtained through cloudsix ROMDatabase db = ROMDatabase.Current; //check to make sure there is a rom with matching name ROMDBEntry entry = null; string extension = Path.GetExtension(actualName).ToLower(); if (extension == ".sgm") { entry = db.GetROMFromSavestateName(actualName); } else if (extension == ".sav") { entry = db.GetROMFromSRAMName(actualName); } if (entry == null) //no matching file name { MessageBox.Show(AppResources.NoMatchingNameText, AppResources.ErrorCaption, MessageBoxButton.OK); return; } //check to make sure format is right if (extension == ".sgm") { string slot = actualName.Substring(actualName.Length - 5, 1); int parsedSlot = 0; if (!int.TryParse(slot, out parsedSlot)) { MessageBox.Show(AppResources.ImportSavestateInvalidFormat, AppResources.ErrorCaption, MessageBoxButton.OK); return; } } //set status bar var indicator = SystemTray.GetProgressIndicator(page); indicator.IsIndeterminate = true; indicator.Text = String.Format(AppResources.ImportingProgressText, actualName); StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFolder romFolder = await localFolder.CreateFolderAsync(ROM_DIRECTORY, CreationCollisionOption.OpenIfExists); StorageFolder saveFolder = await romFolder.CreateFolderAsync(FileHandler.SAVE_DIRECTORY, CreationCollisionOption.OpenIfExists); //if arrive here, entry cannot be null, we can copy the file IStorageFile file = null; if (extension == ".sgm") { file = await SharedStorageAccessManager.CopySharedFileAsync(saveFolder, Path.GetFileNameWithoutExtension(entry.FileName) + actualName.Substring(actualName.Length - 5), NameCollisionOption.ReplaceExisting, fileID); } else if (extension == ".sav") { file = await SharedStorageAccessManager.CopySharedFileAsync(saveFolder, Path.GetFileNameWithoutExtension(entry.FileName) + ".sav", NameCollisionOption.ReplaceExisting, fileID); entry.SuspendAutoLoadLastState = true; } //update database if (extension == ".sgm") { String number = actualName.Substring(actualName.Length - 5, 1); int slot = int.Parse(number); if (entry != null) //NULL = do nothing { SavestateEntry saveentry = db.SavestateEntryExisting(entry.FileName, slot); if (saveentry != null) { //delete entry db.RemoveSavestateFromDB(saveentry); } SavestateEntry ssEntry = new SavestateEntry() { ROM = entry, Savetime = DateTime.Now, Slot = slot, FileName = actualName }; db.Add(ssEntry); db.CommitChanges(); } } #if GBC indicator.Text = AppResources.ApplicationTitle2; #else indicator.Text = AppResources.ApplicationTitle; #endif indicator.IsIndeterminate = false; MessageBox.Show(String.Format(AppResources.ImportCompleteText, entry.DisplayName)); return; }
/// <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); } }
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."); } }