Exemple #1
0
        private void InitStorage()
        {
            if (!StorageFileHelper.FolderExists("books"))
            {
                StorageFileHelper.CreateFolder("books");
            }

            using (var db = new DataBase.DataBase())
            {
                if (!db.DatabaseExists())
                {
                    try
                    {
                        db.CreateDatabase();
                    }
                    catch
                    {
                        db.Dispose();
                        if (StorageFileHelper.FileExists("DB.sdf"))
                        {
                            StorageFileHelper.DeleteFile("DB.sdf");
                        }
                    }
                }
            }
        }
        async void AddFilesToBookList(IReadOnlyList <StorageFile> files)
        {
            var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("books", CreationCollisionOption.OpenIfExists);

            foreach (var file in files)
            {
                if (StorageFileHelper.FileExists(System.IO.Path.Combine("books", file.Name)))
                {
                    continue;
                }
                var newFile = await file.CopyAsync(folder, file.Name, NameCollisionOption.ReplaceExisting);

                var size = (await newFile.GetBasicPropertiesAsync()).Size;
                var item = new BookInfo()
                {
                    Title        = newFile.DisplayName,
                    Position     = 0,
                    Length       = (int)size,
                    Location     = newFile.Path,
                    LastReadTime = DateTime.Now,
                };
                ViewModel.AddBook(item);
            }
        }