Example #1
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);
        }
Example #2
0
        private List <SkyDriveListItem> GetFilesInArchive(SkyDriveListItem item)
        {
            List <SkyDriveListItem> listItems = new List <SkyDriveListItem>();

            if (item.Stream != null)
            {
                //get list of file
                IArchive archive = null;

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

                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 = GetSkyDriveItemType(substrName);
                        }

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

                        SkyDriveListItem listItem = new SkyDriveListItem()
                        {
                            Name       = name,
                            SkyDriveID = "",
                            Type       = type,
                            ParentID   = item.SkyDriveID,
                            Stream     = data
                        };

                        listItems.Add(listItem);
                    }
                }

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

            return(listItems);
        }
 static protected bool IsType(SkyDriveBag item, SkyDriveItemType type)
 {
     return ((string)item[TYPE_KEY] == Enum.GetName(typeof(SkyDriveItemType), type));
 }
Example #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();
                            if (substrName.Equals(".gb") || substrName.Equals(".gbc") || substrName.Equals(".gba"))
                            {
                                type = SkyDriveItemType.ROM;
                            }
                            else if (substrName.Equals(".sgm"))
                            {
                                type = SkyDriveItemType.Savestate;
                            }
                            else if (substrName.Equals(".sav"))
                            {
                                type = SkyDriveItemType.SRAM;
                            }
                        }

                        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);
        }
Example #5
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);
        }