Exemplo n.º 1
0
        public static async Task FillDatabaseAsync()
        {
            ROMDatabase   db          = ROMDatabase.Current;
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFolder romFolder   = await localFolder.GetFolderAsync(ROM_DIRECTORY);

            IReadOnlyList <StorageFile> roms = await romFolder.GetFilesAsync();

            foreach (var file in roms)
            {
                ROMDBEntry entry = FileHandler.InsertNewDBEntry(file.Name);
                await FileHandler.FindExistingSavestatesForNewROM(entry);
            }
            db.CommitChanges();
        }
Exemplo n.º 2
0
        //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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public static async Task ImportROM(ImportFileItem item, DependencyObject page)
        {
            var indicator = SystemTray.GetProgressIndicator(page);

            indicator.IsIndeterminate = true;
            indicator.Text            = String.Format(AppResources.ImportingProgressText, item.Name);

            try
            {
                StorageFolder folder    = ApplicationData.Current.LocalFolder;
                StorageFolder romFolder = await folder.CreateFolderAsync("roms", CreationCollisionOption.OpenIfExists);


                ROMDatabase db          = ROMDatabase.Current;
                var         romEntry    = db.GetROM(item.Name);
                bool        fileExisted = false;
                if (romEntry != null)
                {
                    fileExisted = true;
                    //MessageBox.Show(String.Format(AppResources.ROMAlreadyExistingError, item.Name), AppResources.ErrorCaption, MessageBoxButton.OK);
                    //return;
                }


                if (item.Stream != null)
                {
                    byte[]      tmpBuf          = new byte[32];
                    StorageFile destinationFile = await romFolder.CreateFileAsync(item.Name, CreationCollisionOption.ReplaceExisting);

                    using (IRandomAccessStream destStream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
                        using (DataWriter writer = new DataWriter(destStream))
                        {
                            if (item.Stream.CanSeek)
                            {
                                item.Stream.Seek(0, SeekOrigin.Begin);
                            }
                            while (item.Stream.Read(tmpBuf, 0, tmpBuf.Length) != 0)
                            {
                                writer.WriteBytes(tmpBuf);
                            }


                            await writer.StoreAsync();

                            await writer.FlushAsync();

                            writer.DetachStream();
                        }

                    item.Downloading = false;
                    if (!fileExisted)
                    {
                        var entry = FileHandler.InsertNewDBEntry(destinationFile.Name);
                        await FileHandler.FindExistingSavestatesForNewROM(entry);

                        db.CommitChanges();
                    }

                    //update voice command list
                    await MainPage.UpdateGameListForVoiceCommand();

                    MessageBox.Show(String.Format(AppResources.DownloadCompleteText, item.Name));
                }
                else
                {
                    MessageBox.Show(String.Format(AppResources.DownloadErrorText, item.Name, "Import error"), AppResources.ErrorCaption, MessageBoxButton.OK);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, AppResources.ErrorCaption, MessageBoxButton.OK);
            }
#if GBC
            indicator.Text = AppResources.ApplicationTitle2;
#else
            indicator.Text = AppResources.ApplicationTitle;
#endif
            indicator.IsIndeterminate = false;
        }
Exemplo n.º 5
0
        private async Task DownloadFile(SkyDriveListItem item, LiveConnectClient client)
        {
            StorageFolder folder    = ApplicationData.Current.LocalFolder;
            StorageFolder romFolder = await folder.CreateFolderAsync("roms", CreationCollisionOption.OpenIfExists);

            String path = romFolder.Path;

            ROMDatabase db          = ROMDatabase.Current;
            var         romEntry    = db.GetROM(item.Name);
            bool        fileExisted = false;

            if (romEntry != null)
            {
                fileExisted = true;
                //MessageBox.Show(String.Format(AppResources.ROMAlreadyExistingError, item.Name), AppResources.ErrorCaption, MessageBoxButton.OK);
                //return;
            }

            var indicator = new ProgressIndicator()
            {
                IsIndeterminate = true,
                IsVisible       = true,
                Text            = String.Format(AppResources.DownloadingProgressText, item.Name)
            };

            SystemTray.SetProgressIndicator(this, indicator);

            LiveDownloadOperationResult e = await client.DownloadAsync(item.SkyDriveID + "/content");

            if (e != null)
            {
                byte[]      tmpBuf          = new byte[e.Stream.Length];
                StorageFile destinationFile = await romFolder.CreateFileAsync(item.Name, CreationCollisionOption.ReplaceExisting);

                using (IRandomAccessStream destStream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
                    using (DataWriter writer = new DataWriter(destStream))
                    {
                        while (e.Stream.Read(tmpBuf, 0, tmpBuf.Length) != 0)
                        {
                            writer.WriteBytes(tmpBuf);
                        }
                        await writer.StoreAsync();

                        await writer.FlushAsync();

                        writer.DetachStream();
                    }
                e.Stream.Close();
                item.Downloading = false;
                SystemTray.GetProgressIndicator(this).IsVisible = false;
                if (!fileExisted)
                {
                    var entry = FileHandler.InsertNewDBEntry(destinationFile.Name);
                    await FileHandler.FindExistingSavestatesForNewROM(entry);

                    db.CommitChanges();
                }
                MessageBox.Show(String.Format(AppResources.DownloadCompleteText, item.Name));
            }
            else
            {
                SystemTray.GetProgressIndicator(this).IsVisible = false;
                MessageBox.Show(String.Format(AppResources.DownloadErrorText, item.Name, "Api error"), AppResources.ErrorCaption, MessageBoxButton.OK);
            }
        }