public async static Task <uint> PLibI(KnownLibraryId id)
        {
            uint count = 0;

            try
            {
                var Library = await StorageLibrary.GetLibraryAsync(id);

                // Bind the FoldersListView to the list of folders that make up the library
                var lfolders = Library.Folders;
                foreach (var folder in lfolders)
                {
                    if (folder != null)
                    {
                        var pth = folder.Path;
                        await Task.Run(() => count += FCount(pth, "\\*"));
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"PLibI Exception {ex.Message}");
            }

            return(count);
        }
Example #2
0
        public async Task DeleteFile(KnownLibraryId libraryId, string fileName)
        {
            var lib = await StorageLibrary.GetLibraryAsync(libraryId);
            var result = await lib.SaveFolder.TryGetItemAsync(fileName);

            if (result != null)
            {
                await result.DeleteAsync();
            }
        }
Example #3
0
        public override async void Execute(object parameter)
        {
#if WINDOWS_APP
            KnownLibraryId id  = (KnownLibraryId)parameter;
            var            lib = await StorageLibrary.GetLibraryAsync(id);

            await lib.RequestAddFolderAsync();

            await Locator.SettingsVM.GetLibrariesFolders();
#endif
        }
Example #4
0
        public override async void Execute(object parameter)
        {
            KnownLibraryId id  = (KnownLibraryId)parameter;
            var            lib = await StorageLibrary.GetLibraryAsync(id);

            await lib.RequestAddFolderAsync();

            await Locator.SettingsVM.GetVideoLibraryFolders();

            await Locator.SettingsVM.GetMusicLibraryFolders();
        }
Example #5
0
        public static async Task <StorageLibrary> TryAccessLibraryAsync(KnownLibraryId library)
        {
            try
            {
                return(await StorageLibrary.GetLibraryAsync(library));
            }
            catch (UnauthorizedAccessException)
            {
                ContentDialog unauthorizedAccessDialog = new ContentDialog()
                {
                    Title             = "Unauthorized Access",
                    Content           = string.Format("\r\nTo access the {0} library, go to Settings and enable access. \r\nMake sure that changes has been saved.", library),
                    PrimaryButtonText = "OK"
                };

                await unauthorizedAccessDialog.ShowAsync();
            }
            return(null);
        }
Example #6
0
 public async Task<StorageFile> CreateStorageFile(string artist, string title, KnownLibraryId libraryId)
 {
     string fileExtension = string.Empty;
     if (libraryId == KnownLibraryId.Music)
     {
         fileExtension = ".mp3";
     }
     else if (libraryId == KnownLibraryId.Videos)
     {
         fileExtension = ".mp4";
     }
     var fileName = this.CreateFileName(artist, title, fileExtension);
     var library = await Windows.Storage.StorageLibrary.GetLibraryAsync(libraryId);
     var saveFolder = library.SaveFolder;
     var storageFile = await saveFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
     return storageFile;
 }
Example #7
0
        public async Task <StorageFile> CreateStorageFile(string artist, string title, KnownLibraryId libraryId)
        {
            string fileExtension = string.Empty;

            if (libraryId == KnownLibraryId.Music)
            {
                fileExtension = ".mp3";
            }
            else if (libraryId == KnownLibraryId.Videos)
            {
                fileExtension = ".mp4";
            }
            var fileName = this.CreateFileName(artist, title, fileExtension);
            var library  = await Windows.Storage.StorageLibrary.GetLibraryAsync(libraryId);

            var saveFolder  = library.SaveFolder;
            var storageFile = await saveFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

            return(storageFile);
        }
Example #8
0
        public async Task <List <BaseItem> > GetChangesFromChangeTracker(KnownLibraryId libraryId, FolderAssociation association, List <StorageLibraryChangeType> supportedChangeTypes)
        {
            var result  = new List <BaseItem>();
            var library = await StorageLibrary.GetLibraryAsync(libraryId);

            library.ChangeTracker.Enable();
            _changeReader = library.ChangeTracker.GetChangeReader();
            var changes = await _changeReader.ReadBatchAsync();

            foreach (var change in changes)
            {
                if (change.ChangeType == StorageLibraryChangeType.ChangeTrackingLost)
                {
                    await LogHelper.Write($"Changetracking lost: {change.Path}");

                    library.ChangeTracker.Reset();
                    return(null);
                }
                try
                {
                    if (supportedChangeTypes.Contains(change.ChangeType))
                    {
                        Debug.WriteLine($"File: {change.Path} ChangeType: {change.ChangeType}");
                        if (change.Path.EndsWith("thumb"))
                        {
                            continue;
                        }
                        var file = await change.GetStorageItemAsync();

                        if (file == null && change.ChangeType == StorageLibraryChangeType.Deleted)
                        {
                            var localItem = new LocalItem();
                            localItem.Association = association;
                            localItem.EntityId    = change.Path;
                            result.Add(localItem);
                        }
                        else if (file == null || file.IsOfType(StorageItemTypes.Folder))
                        {
                            await LogHelper.Write($"Skipping {change.Path}");
                        }
                        else
                        {
                            try
                            {
                                //check if the file is currently in use, for example a video currently being recorded
                                var stream = await((StorageFile)file).OpenStreamForWriteAsync();
                                stream.Dispose();
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                            var props = await file.GetBasicPropertiesAsync();

                            var item = new LocalItem(association, file, props);

                            if (change.ChangeType == StorageLibraryChangeType.ContentsChanged)
                            {
                                //for some reason something is writing to the files after the upload, but without making changes
                                var existingItem = ItemTableModel.GetDefault().GetItem(item);
                                if (existingItem?.Size == item.Size)
                                {
                                    continue;
                                }
                            }
                            result.Add(item);
                        }
                    }
                }
                catch (Exception e)
                {
                    await LogHelper.Write($"InstantUpload: {e.Message} File: {change.Path} ChangeType: {change.ChangeType}");

                    await LogHelper.Write(e.StackTrace);
                }
            }
            return(result);
        }
Example #9
0
 public async Task<bool> MediaFileExists(KnownLibraryId libraryId, string fileName)
 {
     var lib = await StorageLibrary.GetLibraryAsync(libraryId);
     var result = await lib.SaveFolder.TryGetItemAsync(fileName);
     return result != null;
 }