Ejemplo n.º 1
0
        //private async Task<int> itterateThruEachFolder(StorageFolder rootFolder)
        //{
            
        //    var folders = await rootFolder.GetFoldersAsync();

        //    int runningCounter = 0;
        //    foreach (var folder in folders)
        //    {
        //        // go thru folders in folder
        //        var returnedRunningCountForFolder = await itterateThruEachFolder(folder);
        //        runningCounter += returnedRunningCountForFolder;

        //        // go thru files in folder
        //        var returnedFileCountInFolder = await getFileCountInFolder(folder);
        //        runningCounter += returnedFileCountInFolder;
        //    }


        //    return runningCounter;
        //}

        private async Task<List<MediaItem>> itterateThruEachFolderAsync(StorageFolder rootFolder, MediaItem parentMediaItem)
        {
            
            var folders = await rootFolder.GetFoldersAsync();

            List<MediaItem> runningList = new List<MediaItem>();
            foreach (var folder in folders)
            {
                //record folder
                MediaItem mi = new MediaItem();
                mi.Name = folder.Name;
                mi.ParentName = rootFolder.Name;
                mi.Type = 5;
                mi.Children = new List<MediaItem>();
                mi.rawStorageFolder = folder;
                parentMediaItem.Children.Add(mi);
                //runningList.Add(mi);

                //// go thru folders in folder
                //var returnedRunningList = await itterateThruEachFolderAsync(folder, mi);
                //runningList.AddRange(returnedRunningList);

                // go thru files in folder
                var files = await getFilesInFolderAsync(folder, mi);
                //runningList.AddRange(files);
            }


            return runningList;
        }
Ejemplo n.º 2
0
        //private async Task<int> getFileCountInFolder(StorageFolder folder)
        //{
        //    var fileCount = 0;
        //    var files = await folder.GetFilesAsync();
        //    foreach (var file in files)
        //    {
        //        fileCount++;
        //    }


        //    return fileCount;
        //}

        private async Task<List<MediaItem>> getFilesInFolderAsync(StorageFolder folder, MediaItem parentMediaItem)
        {
            List<MediaItem> mediaItems = new List<MediaItem>(); 
            var files = await folder.GetFilesAsync();

            foreach (var file in files)
            {
                //record file
                MediaItem mi = new MediaItem();
                mi.Name = file.Name;
                mi.ParentName = folder.Name;
                mi.Type = 10;
                mi.rawStorageFile = file;
                mi.Children = new List<MediaItem>();

                parentMediaItem.Children.Add(mi);
                //mediaItems.Add(mi);
            }


            return mediaItems;
        }
Ejemplo n.º 3
0
        //private async Task<int> getMediaAsync()
        //{
        //    int count = 0;

        //    var folders = await Windows.Storage.KnownFolders.RemovableDevices.GetFoldersAsync();
        //    foreach (var storageFolder in folders)
        //    {
        //        var files = await storageFolder.GetFilesAsync();

        //        foreach (var file in files)
        //        {
        //            count++;
        //        }
                
        //    }

        //    return count;
        //}

        //private async Task<int> getMediaManuallyAsync()
        //{
        //    int count = 0;

        //    // Get all removable devices
        //    var selector = Windows.Devices.Portable.StorageDevice.GetDeviceSelector();
        //    var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selector);

        //    foreach (Windows.Devices.Enumeration.DeviceInformation device in devices)
        //    {
        //        // Get device root folder
        //        StorageFolder rootFolder = Windows.Devices.Portable.StorageDevice.FromId(device.Id);

        //        //string myFile = Path.Combine(Package.Current.InstalledLocation.Path, "Content/MyTest1.txt");
        //        string myFile = rootFolder.Provider.DisplayName + @"\" + rootFolder.Name + @"\Phone\Music";
        //        StorageFolder myFolder = await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(myFile));

        //        //using (Stream s = await myFolder.OpenStreamForReadAsync(Path.GetFileName(myFile)))
        //        //{
        //        //    using (StreamReader sr = new StreamReader(s))
        //        //    {
        //        //        // do whateve you want
        //        //    }
        //        //}

        //    }


        //    return count;
        //}


        //private async Task<int> getMusicAsync() {
        //    int count = 0;

        //    var folders = await Windows.Storage.KnownFolders.MusicLibrary.GetFoldersAsync();
        //    foreach (var storageFolder in folders)
        //    {
        //        //var files = await storageFolder.GetFilesAsync();

        //        //foreach (var file in files)
        //        //{
        //        //    count++;
        //        //}

        //    }
        //    return count;
        //}



 
        private async Task<int> getMediaViaDevicesAsync() {

            
            List<MediaItem> runningList = new List<MediaItem>();
           
            
            // Get all removable devices
            var selector = Windows.Devices.Portable.StorageDevice.GetDeviceSelector();
            var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selector);

            foreach (Windows.Devices.Enumeration.DeviceInformation device in devices)
            {
                // Get device root folder
                StorageFolder rootFolder = Windows.Devices.Portable.StorageDevice.FromId(device.Id);

                var folders = await rootFolder.GetFoldersAsync();

                foreach (var folder in folders)
                {

                    var folders2 = await folder.GetFoldersAsync();

                    
                    foreach (var folder2 in folders2)
                    {
                        //record folder
                        MediaItem mi = new MediaItem();
                        mi.Name = folder2.Name;
                        mi.ParentName = folder.Name;
                        mi.Type = 3;
                        mi.rawStorageFolder = folder2;
                        mi.Children = new List<MediaItem>();
                        runningList.Add(mi);

                        ////itterate thru each folder and get its folders/files
                        //var ret = await itterateThruEachFolderAsync(folder2, mi);

                        
                    }

                    if (runningList.Count > 0)
                    {
                        lbMediaFolders.ItemsSource = runningList;
                    }

                }

            }

            return success;

        }