Ejemplo n.º 1
0
        async void skydriveList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ImportFileItem item = this.skydriveList.SelectedItem as ImportFileItem;

            if (item == null)
            {
                return;
            }

            ROMDatabase db = ROMDatabase.Current;


            if (item.Type == SkyDriveItemType.ROM)
            {
                if (item.Stream != null)
                {
                    await SkyDriveImportPage.ImportROM(item, this);
                }
            }

            else if (item.Type == SkyDriveItemType.Savestate || item.Type == SkyDriveItemType.SRAM)
            {
                //check to make sure there is a rom with matching name
                ROMDBEntry entry = null;

                if (item.Type == SkyDriveItemType.Savestate)  //save state
                {
                    entry = db.GetROMFromSavestateName(item.Name);
                }
                else if (item.Type == SkyDriveItemType.SRAM) //sram
                {
                    entry = db.GetROMFromSRAMName(item.Name);
                }

                if (entry == null) //no matching file name
                {
                    MessageBox.Show(AppResources.NoMatchingNameText, AppResources.ErrorCaption, MessageBoxButton.OK);
                    return;
                }

                //check to make sure format is right
                if (item.Type == SkyDriveItemType.Savestate)  //save state
                {
                    string slot       = item.Name.Substring(item.Name.Length - 5, 1);
                    int    parsedSlot = 0;
                    if (!int.TryParse(slot, out parsedSlot))
                    {
                        MessageBox.Show(AppResources.ImportSavestateInvalidFormat, AppResources.ErrorCaption, MessageBoxButton.OK);
                        return;
                    }
                }



                if (item.Stream != null)
                {
                    await SkyDriveImportPage.ImportSave(item, this);
                }
            }
        }
Ejemplo n.º 2
0
        async void skydriveList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SDCardListItem item = this.skydriveList.SelectedItem as SDCardListItem;

            if (item == null)
            {
                return;
            }

            ROMDatabase db = ROMDatabase.Current;

            if (item.isFolder)
            {
                this.skydriveList.ItemsSource = null;
                this.currentFolderBox.Text    = item.Name;
                this.OpenFolder(item.ThisFolder);
            }

            else  //file
            {
                if (item.Type == SkyDriveItemType.Zip || item.Type == SkyDriveItemType.Rar || item.Type == SkyDriveItemType.SevenZip)
                {
                    this.skydriveList.ItemsSource = null;
                    this.currentFolderBox.Text    = item.Name;
                    this.downloadsInProgress++;

                    await this.DownloadFile(item);

                    try
                    {
                        List <SDCardListItem> listItems;

                        listItems = this.GetFilesInArchive(item);

                        this.skydriveStack.Add(listItems);
                        this.skydriveList.ItemsSource = listItems;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, AppResources.ErrorCaption, MessageBoxButton.OK);
                    }

                    this.downloadsInProgress--;
                }

                else if (item.Type == SkyDriveItemType.ROM)
                {
                    // Download
                    if (!item.Downloading)
                    {
                        this.downloadsInProgress++;
                        if (item.Stream == null)
                        {
                            await this.DownloadFile(item);
                        }


                        await SkyDriveImportPage.ImportROM(item, this);

                        this.downloadsInProgress--;
                    }
                    else
                    {
                        MessageBox.Show(AppResources.AlreadyDownloadingText, AppResources.ErrorCaption, MessageBoxButton.OK);
                    }
                }

                else if (item.Type == SkyDriveItemType.Savestate || item.Type == SkyDriveItemType.SRAM)
                {
                    //check to make sure there is a rom with matching name
                    ROMDBEntry entry = null;

                    if (item.Type == SkyDriveItemType.Savestate)  //save state
                    {
                        entry = db.GetROMFromSavestateName(item.Name);
                    }
                    else if (item.Type == SkyDriveItemType.SRAM) //sram
                    {
                        entry = db.GetROMFromSRAMName(item.Name);
                    }

                    if (entry == null) //no matching file name
                    {
                        MessageBox.Show(AppResources.NoMatchingNameText, AppResources.ErrorCaption, MessageBoxButton.OK);
                        return;
                    }

                    //check to make sure format is right
                    if (item.Type == SkyDriveItemType.Savestate)  //save state
                    {
                        string slot       = item.Name.Substring(item.Name.Length - 5, 1);
                        int    parsedSlot = 0;
                        if (!int.TryParse(slot, out parsedSlot))
                        {
                            MessageBox.Show(AppResources.ImportSavestateInvalidFormat, AppResources.ErrorCaption, MessageBoxButton.OK);
                            return;
                        }
                    }

                    // Download
                    if (!item.Downloading)
                    {
                        this.downloadsInProgress++;

                        if (item.Stream == null)
                        {
                            await this.DownloadFile(item);
                        }

                        await SkyDriveImportPage.ImportSave(item, this);

                        this.downloadsInProgress--;
                    }
                    else
                    {
                        MessageBox.Show(AppResources.AlreadyDownloadingText, AppResources.ErrorCaption, MessageBoxButton.OK);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private async Task <List <ImportFileItem> > GetFilesInArchive(SkyDriveItemType parentType, IStorageFile file)
        {
            List <ImportFileItem> listItems = new List <ImportFileItem>();

            if (file != null)
            {
                IRandomAccessStream accessStream = await file.OpenReadAsync();

                Stream s = accessStream.AsStreamForRead((int)accessStream.Size);

                //get list of file
                IArchive archive = null;

                if (parentType == SkyDriveItemType.Rar)
                {
                    archive = SharpCompress.Archive.Rar.RarArchive.Open(s);
                }
                else if (parentType == SkyDriveItemType.Zip)
                {
                    archive = SharpCompress.Archive.Zip.ZipArchive.Open(s);
                }
                else if (parentType == SkyDriveItemType.SevenZip)
                {
                    archive = SharpCompress.Archive.SevenZip.SevenZipArchive.Open(s);
                }

                foreach (var entry in archive.Entries)
                {
                    if (!entry.IsDirectory)
                    {
                        Stream data = new MemoryStream();
                        entry.WriteTo(data);
                        data.Position = 0;
                        String name = entry.FilePath;

                        SkyDriveItemType type = SkyDriveItemType.File;
                        int dotIndex          = -1;
                        if ((dotIndex = name.LastIndexOf('.')) != -1)
                        {
                            String substrName = name.Substring(dotIndex).ToLower();
                            type = SkyDriveImportPage.GetSkyDriveItemType(substrName);
                        }

                        if (type == SkyDriveItemType.File)
                        {
                            data.Close();
                            continue;
                        }

                        ImportFileItem listItem = new ImportFileItem()
                        {
                            Name   = name,
                            Type   = type,
                            Stream = data
                        };

                        listItems.Add(listItem);
                    }
                }

                //close the zip stream since we have the stream of each item inside it already
                s.Close();
                s = null;
            }

            return(listItems);
        }
Ejemplo n.º 4
0
        private List <SDCardListItem> GetFilesInArchive(SDCardListItem item)
        {
            List <SDCardListItem> listItems = new List <SDCardListItem>();


            if (item.Stream != null)
            {
                //fix SD card stream bug
                Stream s = new MemoryStream();
                item.Stream.CopyTo(s);
                s.Position = 0;
                item.Stream.Close();// close because we copy it to s already
                item.Stream = null;

                //get list of file
                IArchive archive = null;

                if (item.Type == SkyDriveItemType.Rar)
                {
                    archive = SharpCompress.Archive.Rar.RarArchive.Open(s);
                }
                else if (item.Type == SkyDriveItemType.Zip)
                {
                    archive = SharpCompress.Archive.Zip.ZipArchive.Open(s);
                }
                else if (item.Type == SkyDriveItemType.SevenZip)
                {
                    archive = SharpCompress.Archive.SevenZip.SevenZipArchive.Open(s);
                }


                foreach (var entry in archive.Entries)
                {
                    if (!entry.IsDirectory)
                    {
                        Stream data = new MemoryStream();
                        entry.WriteTo(data);
                        data.Position = 0;
                        String name = entry.FilePath;

                        SkyDriveItemType type = SkyDriveItemType.File;
                        int dotIndex          = -1;
                        if ((dotIndex = name.LastIndexOf('.')) != -1)
                        {
                            String substrName = name.Substring(dotIndex).ToLower();
                            type = SkyDriveImportPage.GetSkyDriveItemType(substrName);
                        }

                        if (type == SkyDriveItemType.File)
                        {
                            data.Close();
                            continue;
                        }

                        SDCardListItem listItem = new SDCardListItem()
                        {
                            Name       = name,
                            Type       = type,
                            isFolder   = false,
                            ParentPath = item.ThisFile.Path,
                            Stream     = data
                        };

                        listItems.Add(listItem);
                    }
                }

                //close the zip stream since we have the stream of each item inside it already
                s.Close();
            }

            return(listItems);
        }