file360

Log | Files | Refs

FileLister.cs (15921B)


      1 namespace File360 {
      2     /*
      3      * FileLister provides the UI component for 
      4      * interacting with files
      5      */
      6     public class sealed FileLister {
      7         /*
      8          * filePath setter updates the UI
      9          */
     10         public string filePath {get; set;}
     11         public FileLister(){
     12             //SDLoad.Begin();
     13             //PhoneLoad.Begin();
     14             GetSDRoot();
     15             //gridScrollViewer = SDGridView.GetFirstLogicalChildByType<ScrollViewer>(false);
     16             //gridScrollViewer.VerticalScrollMode = ScrollMode.Auto;
     17             //LoadMemoryData();
     18             //SettingsTab.Height = Window.Current.Bounds.Width * 2 / 3;
     19             //PasteFlipView.SelectionChanged += PasteBarSelectionChanged;
     20             //AppearancePanel.Begin();
     21             //SubFrame.ContentTransitions = new TransitionCollection { new PaneThemeTransition { Edge = EdgeTransitionLocation.Bottom } };
     22         }
     23 
     24         private async void GetSDRoot()
     25         {
     26             if (ApplicationData.Current.LocalSettings.Values.ContainsKey("FolderTokenSettingsKey"))
     27             {
     28                 string token = (string)ApplicationData.Current.LocalSettings.Values["FolderTokenSettingsKey"];
     29                 // if we do, use it to get the StorageFolder instance
     30                 folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(token);
     31                 this.Addresser.Reset();
     32                 try
     33                 {
     34                     GetFilesAndFolder(folder);
     35                     RootFolder.Text = "3";
     36                     IsMusicLibraryOpen = false;
     37                     IsVideoLibraryOpen = false;
     38                     IsPictureLibraryOpen = false;
     39                 }
     40                 catch (Exception ex)
     41                 {
     42                     ShowStatus(ex.Message);
     43                     //AI("no sdcard is detected", 2);
     44                 }
     45             }
     46         }
     47 
     48         public async void GetFilesAndFolder(IStorageFolder anyFolder)
     49         {
     50             await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async delegate
     51             {
     52                 ShowStatus(anyFolder.Path);
     53                 if (anyFolder != null)
     54                 {
     55                     Items = null;
     56                     sd.Clear();
     57                     SDGridView.ItemsSource = null;
     58                     CurrentFolder = anyFolder;
     59                     Items = await anyFolder.GetItemsAsync();
     60                     if (Items.Count == 0)
     61                     {
     62                         CurrentFolder = anyFolder;
     63                         headerText.Text = anyFolder.Name;
     64                         sd.Clear();
     65                         switch (anyFolder.Path)
     66                         {
     67                             case @"D:\Documents":
     68                                 //display documents missing sad face
     69                                 break;
     70                             case @"D:\Music":
     71                                 //display music missing sad face
     72                                 break;
     73                             case @"D:\Videos":
     74                                 //display videos missing sad face
     75                                 break;
     76                             case @"D:\Pictures":
     77                                 //display pictures missing sad face
     78                                 break;
     79                             default:
     80                                 EmptyFolderStack.Visibility = Visibility.Visible;
     81                                 //default options for other empty folders
     82                                 break;
     83 
     84                         }
     85                         return;
     86                     }
     87                     //if (GridType)
     88                     //    SDGridView.ItemsPanel = (ItemsPanelTemplate)Resources["GridViewItemsPanel"];
     89                     //else SDGridView.ItemsPanel = (ItemsPanelTemplate)Resources["ListViewItemsPanel"];
     90                     else
     91                     {
     92                         EmptyFolderStack.Visibility = Visibility.Collapsed;
     93                         foreach (IStorageItem Data in Items)
     94                         {
     95                             if (Data.IsOfType(StorageItemTypes.Folder))
     96                             {
     97                                 IStorageFolder Folder;
     98                                 Folder = (IStorageFolder)Data;
     99                                 //IReadOnlyList<IStorageItem> item = await Folder.GetItemsAsync();
    100                                 headerText.Text = anyFolder.Name;
    101                                 if (CurrentFolder.Path == @"D:\")
    102                                 {
    103                                     if (Folder.Name == "Videos") sd.Add(new sdlist(Folder.Name, "o", ""));
    104                                     else if (Folder.Name == "Pictures") sd.Add(new sdlist(Folder.Name, "f", ""));
    105                                     else if (Folder.Name == "Music") sd.Add(new sdlist(Folder.Name, "g", ""));
    106                                     else if (Folder.Name == "Downloads") sd.Add(new sdlist(Folder.Name, "e", ""));
    107                                     else if (Folder.Name == "Documents") sd.Add(new sdlist(Folder.Name, "n", ""));
    108                                     else sd.Add(new sdlist(Folder.Name, "h", ""));
    109                                 }
    110                                 else sd.Add(new sdlist(Folder.Name, "h", ""));
    111                             }
    112                             if (Data.IsOfType(StorageItemTypes.File))
    113                             {
    114                                 IStorageFile File = (IStorageFile)Data;
    115                                 string fn = File.Name;
    116                                 string fi = File.FileType;
    117                                 #region FileTypes
    118                                 if (fi == ".mp3")
    119                                 {
    120                                     if (((string)settings.Values["musThumbnail"] == "1"))
    121                                     {
    122 
    123                                         #region Mp3
    124 
    125                                         //var fileStream = await File.OpenStreamForReadAsync();
    126                                         //var tagFile = TagLib.File.Create(new StreamFileAbstraction(File.Name, fileStream, fileStream));
    127                                         //var tags = tagFile.GetTag(TagTypes.Id3v2);
    128                                         //try
    129                                         //{
    130                                         //    if (tags.Pictures != null)
    131                                         //    {
    132                                         //        MemoryStream ms = new MemoryStream(tags.Pictures[0].Data.Data);
    133                                         //        WriteableBitmap wm = null;
    134                                         //        WriteableBitmap wwm = await wm.FromStream(ms, Windows.Graphics.Imaging.BitmapPixelFormat.Unknown);
    135 
    136                                         //        ms.Dispose();
    137                                         //        ImageBrush im = new ImageBrush();
    138                                         //        im.ImageSource = wwm;
    139                                         //        im.Stretch = Stretch.UniformToFill;
    140                                         //        sd.Add(new sdlist(fn, im, ""));
    141                                         //        #endregion
    142                                         //    }
    143                                         //}
    144                                         //catch (IndexOutOfRangeException ex)
    145                                         //{
    146                                         //    BitmapImage bm = new BitmapImage(new Uri("ms-appx:///Assets/IMG-20150528-WA0003.jpg", UriKind.Absolute));
    147                                         //    ImageBrush im = new ImageBrush();
    148                                         //    im.ImageSource = bm;
    149                                         //    sd.Add(new sdlist(fn, im, ""));
    150                                         //}
    151                                         //catch (Exception ex)
    152                                         //{
    153                                         //    AI(ex.Message, 2);
    154                                         //}
    155                                         #endregion
    156                                     }
    157                                     else sd.Add(new sdlist(fn, "m"));
    158 
    159                                 }
    160                                 else if (fi == ".wma")
    161                                 {
    162                                     if (((string)settings.Values["musThumbnail"] == "1"))
    163                                     { }
    164                                     #region wma-work in progress
    165 
    166                                     //var fileStream = await File.OpenStreamForReadAsync();
    167                                     //var tagFile = TagLib.File.Create(new StreamFileAbstraction(File.Name, fileStream, fileStream));
    168                                     //var tags = tagFile.GetTag(TagTypes.Id3v2);
    169                                     //try
    170                                     //{
    171                                     //    if (tags.Pictures != null)
    172                                     //    {
    173                                     //        MemoryStream ms = new MemoryStream(tags.Pictures[0].Data.Data);
    174                                     //        WriteableBitmap wm = null;
    175                                     //        WriteableBitmap wwm = await wm.FromStream(ms, Windows.Graphics.Imaging.BitmapPixelFormat.Unknown);
    176 
    177                                     //        ms.Dispose();
    178                                     //        ImageBrush im = new ImageBrush();
    179                                     //        im.ImageSource = wwm;
    180                                     //        im.Stretch = Stretch.UniformToFill;
    181                                     //        sd.Add(new sdlist(fn, im, ""));
    182                                     //        #endregion
    183                                     //    }
    184                                     //}
    185                                     //catch (IndexOutOfRangeException ex)
    186                                     //{
    187                                     //    BitmapImage bm = new BitmapImage(new Uri("ms-appx:///Assets/IMG-20150528-WA0003.jpg", UriKind.Absolute));
    188                                     //    ImageBrush im = new ImageBrush();
    189                                     //    im.ImageSource = bm;
    190                                     //    sd.Add(new sdlist(fn, im, ""));
    191                                     //}
    192                                     //catch (Exception ex)
    193                                     //{
    194                                     //    AI(ex.Message, 2);
    195                                     //}
    196                                     #endregion
    197                                     else sd.Add(new sdlist(fn, "m"));
    198 
    199                                 }
    200                                 else if (fi == ".docx")
    201                                 {
    202                                     sd.Add(new sdlist(fn, "k"));
    203 
    204                                 }
    205                                 else if (fi == ".png")
    206                                 {
    207                                     if (((string)settings.Values["picThumbnail"] == "1"))
    208                                         await GetThumbnailImageAsync((StorageFile)File, ThumbnailMode.ListView);
    209                                     else sd.Add(new sdlist(fn, "p"));
    210                                 }
    211                                 else if (fi == ".jpg")
    212                                 {
    213                                     if (((string)settings.Values["picThumbnail"] == "1"))
    214                                         await GetThumbnailImageAsync((StorageFile)File, ThumbnailMode.ListView);
    215                                     else sd.Add(new sdlist(fn, "p"));
    216                                 }
    217                                 else if (fi == ".mp4")
    218                                 {
    219                                     if (((string)settings.Values["vidThumbnail"] == "1"))
    220                                     {
    221                                         try
    222                                         {
    223                                             await GetThumbnailImageAsync((StorageFile)File, ThumbnailMode.ListView);
    224                                         }
    225                                         catch
    226                                         {
    227                                             sd.Add(new sdlist(fn, "v"));
    228                                         }
    229                                     }
    230                                     else sd.Add(new sdlist(fn, "v"));
    231                                 }
    232                                 else if (fi == ".mov")
    233                                 {
    234                                     if (((string)settings.Values["vidThumbnail"] == "1"))
    235                                     {
    236                                         try
    237                                         {
    238                                             await GetThumbnailImageAsync((StorageFile)File, ThumbnailMode.ListView);
    239                                         }
    240                                         catch
    241                                         {
    242                                             sd.Add(new sdlist(fn, "v"));
    243                                         }
    244                                     }
    245                                     else sd.Add(new sdlist(fn, "v"));
    246                                 }
    247                                 else if (fi == ".zip")
    248                                 {
    249                                     sd.Add(new sdlist(fn, "z"));
    250 
    251                                 }
    252                                 else if (fi == ".cs")
    253                                 {
    254                                     sd.Add(new sdlist(fn, "c"));
    255                                 }
    256                                 else if (fi == ".pdf")
    257                                 {
    258                                     sd.Add(new sdlist(fn, "b"));
    259                                 }
    260                                 else if (fi == ".vcf")
    261                                 {
    262                                     sd.Add(new sdlist(fn, "l"));
    263                                 }
    264                                 else if (fi == ".doc")
    265                                 {
    266                                     sd.Add(new sdlist(fn, "k"));
    267                                 }
    268                                 else if (fi == ".xlx")
    269                                 {
    270                                     sd.Add(new sdlist(fn, "j"));
    271                                 }
    272                                 else if (fi == ".xlsx")
    273                                 {
    274                                     sd.Add(new sdlist(fn, "j"));
    275                                 }
    276                                 else if (fi == ".7z")
    277                                 {
    278                                     sd.Add(new sdlist(fn, "7"));
    279                                 }
    280                                 else if (fi == ".xml")
    281                                 {
    282                                     sd.Add(new sdlist(fn, "x"));
    283                                 }
    284                                 else if (fi == ".txt")
    285                                 {
    286                                     sd.Add(new sdlist(fn, "a"));
    287                                 }
    288                                 else if (fi == ".rar")
    289                                 {
    290                                     sd.Add(new sdlist(fn, "r"));
    291                                 }
    292                                 else
    293                                 {
    294                                     sd.Add(new sdlist(fn, "i"));
    295 
    296                                 }
    297                                 #endregion
    298                             }
    299                         }
    300                     }
    301                 }
    302                 //else AI("This folder contains no items", 2);
    303                 SDGridView.ItemsSource = sd;
    304             });
    305         }
    306 
    307         
    308     }
    309 }