예제 #1
0
        public static async Task copysample()
        {
            Uri uri = new Uri("ms-appx:///Assets/ab.png");

            Windows.Storage.StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);

            Windows.Storage.StorageFile copiedfile = await file.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "ab.png");

            await Routines.extractFiles(copiedfile);

            uri  = new Uri("ms-appdata:///local/ab/OPS/images/cover.png");
            file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);

            Windows.Storage.StorageFolder imageFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFolderAsync("thumbs");

            await file.CopyAsync(imageFolder, "book0.jpg");

            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            Windows.Storage.ApplicationDataCompositeValue composite = new Windows.Storage.ApplicationDataCompositeValue();
            composite["uniqueid"] = "book0";
            composite["title"]    = "The Arabian Nights";
            composite["author"]   = "Andrew Lang";
            composite["image"]    = "thumbs\\book0.jpg";;
            composite["location"] = "ab";
            var samplebook = new Book(composite["uniqueid"].ToString(), composite["title"].ToString(), composite["author"].ToString(),
                                      composite["image"].ToString(), composite["location"].ToString());

            BookSource.AddBookAsync(samplebook);
            int count = (int)localSettings.Values["bookCount"];

            localSettings.Values["bookCount"] = ++count;
            localSettings.Containers["booksContainer"].Values["book0"] = composite;
        }
예제 #2
0
        public static async Task LoadBooks()
        {
            var  localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            bool config        = true;

            try {
                Windows.Storage.StorageFile firstfile = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("firsttime");
            }
            catch (System.IO.FileNotFoundException)
            {
                await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("firsttime");

                await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("thumbs", CreationCollisionOption.OpenIfExists);

                localSettings.Values.Clear();
                localSettings.Values["bookCount"]   = 0;
                localSettings.Values["thumbFolder"] = "thumbs";
                try
                {
                    localSettings.CreateContainer("booksContainer", Windows.Storage.ApplicationDataCreateDisposition.Existing);
                }
                catch
                {
                    localSettings.CreateContainer("booksContainer", Windows.Storage.ApplicationDataCreateDisposition.Always);
                }
                try
                {
                    await resetFolders();
                }
                catch { }
                await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("firsttime");

                await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("thumbs", CreationCollisionOption.OpenIfExists);

                Windows.Storage.ApplicationDataCompositeValue composite = new Windows.Storage.ApplicationDataCompositeValue();
                composite["uniqueid"] = "";
                composite["location"] = "";
                composite["title"]    = "";
                composite["author"]   = "";
                composite["image"]    = "";
                composite["chapter"]  = "0";
                composite["offset"]   = "0";
                composite["count"]    = "0";
                localSettings.Values["nowReading"] = composite;
                localSettings.Values["color"]      = "White";
                localSettings.Values["fontfamily"] = "Segoe";
                localSettings.Values["fontweight"] = "Normal";
                localSettings.Values["readmode"]   = "pano";
                localSettings.Values["numcols"]    = "One";
                await copysample();

                DisplayMsg("Happy Reading", "No books here. Add books by Right Clicking with mouse or swiping from bottom of your tablet.");
                config = false;
            }

            if (config == true)
            {
                if ((int)localSettings.Values["bookCount"] == 0)
                {
                    DisplayMsg("Happy Reading", "No books here. Add books by Right Clicking with mouse or swiping from bottom of your tablet.");
                }

                if (localSettings.Containers.ContainsKey("booksContainer"))
                {
                    foreach (KeyValuePair <String, object> book in localSettings.Containers["booksContainer"].Values)
                    {
                        Windows.Storage.ApplicationDataCompositeValue currentBook = (Windows.Storage.ApplicationDataCompositeValue)book.Value;
                        var newbook = new Book(currentBook["uniqueid"].ToString(), currentBook["title"].ToString(), currentBook["author"].ToString(),
                                               currentBook["image"].ToString(), currentBook["location"].ToString());
                        BookSource.AddBookAsync(newbook);
                    }
                }
            }
        }