Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronously saves all the album arts in the library.
        /// </summary>
        /// <param name="Data">ID3 tag of the song to get album art data from.</param>
        public static async Task <bool> SaveImagesAsync(Windows.Storage.FileProperties.StorageItemThumbnail thumb, Mediafile file)
        {
            var albumartFolder = ApplicationData.Current.LocalFolder;
            var md5Path        = (file.Album + file.LeadArtist).ToLower().ToSha1();

            if (!File.Exists(albumartFolder.Path + @"\AlbumArts\" + md5Path + ".jpg"))
            {
                try
                {
                    Windows.Storage.Streams.IBuffer buf;
                    Windows.Storage.Streams.Buffer  inputBuffer = new Windows.Storage.Streams.Buffer(1024);
                    var albumart = await albumartFolder.CreateFileAsync(@"AlbumArts\" + md5Path + ".jpg", CreationCollisionOption.FailIfExists).AsTask().ConfigureAwait(false);

                    using (Windows.Storage.Streams.IRandomAccessStream albumstream = await albumart.OpenAsync(FileAccessMode.ReadWrite).AsTask().ConfigureAwait(false))
                    {
                        while ((buf = (await thumb.ReadAsync(inputBuffer, inputBuffer.Capacity, Windows.Storage.Streams.InputStreamOptions.None).AsTask().ConfigureAwait(false))).Length > 0)
                        {
                            await albumstream.WriteAsync(buf).AsTask().ConfigureAwait(false);
                        }
                    }

                    thumb.Dispose();
                    return(true);
                }
                catch (Exception ex)
                {
                    await NotificationManager.ShowAsync(ex.Message + "||" + file.Path);

                    return(false);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Asynchronously saves all the album arts in the library.
        /// </summary>
        /// <param name="Data">ID3 tag of the song to get album art data from.</param>
        public async void SaveImages(Windows.Storage.FileProperties.StorageItemThumbnail thumb, Mediafile file)
        {
            var albumartFolder = ApplicationData.Current.LocalFolder;
            var md5Path        = (file.Album + file.LeadArtist).ToLower().ToSha1();

            if (!File.Exists(albumartFolder.Path + @"\AlbumArts\" + md5Path + ".jpg"))
            {
                IBuffer buf;
                Windows.Storage.Streams.Buffer inputBuffer = new Windows.Storage.Streams.Buffer(1024);
                var albumart = await albumartFolder.CreateFileAsync(@"AlbumArts\" + md5Path + ".jpg", CreationCollisionOption.FailIfExists);

                using (IRandomAccessStream albumstream = await albumart.OpenAsync(FileAccessMode.ReadWrite))
                {
                    while ((buf = (await thumb.ReadAsync(inputBuffer, inputBuffer.Capacity, Windows.Storage.Streams.InputStreamOptions.None))).Length > 0)
                    {
                        await albumstream.WriteAsync(buf);
                    }

                    //try
                    //{
                    //    var data = Data.AttachedPictureFrames["APIC"] as AttachedPictureFrame;
                    //    var stream = data.Data.AsRandomAccessStream();
                    //    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                    //    var x = await decoder.GetSoftwareBitmapAsync();
                    //    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, albumstream);
                    //    encoder.SetSoftwareBitmap(x);
                    //    await encoder.FlushAsync();
                    //    stream.Dispose();
                    //}
                    //catch(Exception ex) { Debug.Write(ex.Message + "||" + file.Path); }
                }
                thumb.Dispose();
            }
        }
Ejemplo n.º 3
0
        private async Task FillNextItemsToList(int pageIndex, int pageSize)
        {
            isFillingList = true;

            StorageFolder            f      = KnownFolders.PicturesLibrary;
            List <StorageFile>       files  = (await f.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByDate, (uint)(pageIndex * pageSize), (uint)pageSize)).ToList();
            List <PicturePickerItem> result = new List <PicturePickerItem>();

            if ((files.Count < pageSize) && (allItems.Count > (pageIndex * pageSize))) //This is the end
            {
                isFillingList = false;
                return;
            }
            else if (files.Count == 0) //We already reached the end
            {
                lastPageIndexLoaded--;
                isFillingList = false;
                return;
            }

            foreach (var file in files)
            {
                Windows.Storage.FileProperties.StorageItemThumbnail thumbnailStream = null;

                try
                {
                    thumbnailStream = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.PicturesView);
                }
                catch (Exception)
                {
                    thumbnailStream = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem);
                }

                if (thumbnailStream != null)
                {
                    var image = new BitmapImage();
                    await image.SetSourceAsync(thumbnailStream);

                    result.Add(new PicturePickerItem {
                        File = file, Thumbnail = image
                    });
                }
                else
                {
                    result.Add(new PicturePickerItem {
                        File = file, Thumbnail = null
                    });
                }
            }

            allItems.AddRange(result);

            isFillingList = false;
        }
Ejemplo n.º 4
0
        public async static Task <List <IOElement> > ParseWindowsFiles(string rawList, string path)
        {
            List <IOElement> files = new List <IOElement>();

            foreach (string item in rawList.Trim().Split('\n'))
            {
                IOElement newElement = new IOElement();

                string trimmedItem = item.Trim();

                int timeEnding = 0;

                for (int i = 8; i < trimmedItem.Length; i++)
                {
                    if (trimmedItem[i] != ' ')
                    {
                        for (int j = i; j < trimmedItem.Length; j++)
                        {
                            if (trimmedItem[i] == ' ')
                            {
                                timeEnding = j;
                                break;
                            }
                        }
                    }
                }

                newElement.LastEdit = trimmedItem.Substring(0, timeEnding).Trim();
                while (newElement.LastEdit.Contains("  "))
                {
                    newElement.LastEdit = newElement.LastEdit.Replace("  ", " ");
                }

                int typeBeginning = 0;
                int typeEnding    = 0;

                for (int i = 17; i < trimmedItem.Length; i++)
                {
                    if (trimmedItem[i] != ' ')
                    {
                        typeBeginning = i;
                        break;
                    }
                }

                for (int i = typeBeginning; i < trimmedItem.Length; i++)
                {
                    if (trimmedItem[i] == ' ')
                    {
                        typeEnding = i;
                        break;
                    }
                }

                newElement.FileType = trimmedItem.Substring(typeBeginning, typeEnding - typeBeginning).Replace("<DIR>", "Directory");

                newElement.IsFile = newElement.FileType != "Directory";

                int nameBeginning = 0;
                for (int i = typeEnding + 1; i < trimmedItem.Length; i++)
                {
                    if (trimmedItem[i] != ' ')
                    {
                        nameBeginning = i;
                        break;
                    }
                }

                newElement.Name = trimmedItem.Substring(nameBeginning, trimmedItem.Length - nameBeginning);

                newElement.Path = path;

                //skip those entries
                if (newElement.Name == "." || newElement.Name == "..")
                {
                    continue;
                }

                ulong size = 0;
                ulong.TryParse(newElement.FileType, out size);

                newElement.Size = size;

                if (size != 0)
                {
                    newElement.FileType = newElement.Name.Split('.').Last();
                }

                if (newElement.IsFile)
                {
                    if (newElement.Name.Contains('.'))
                    {
                        newElement.FileType = newElement.Name.Substring(newElement.Name.LastIndexOf('.'));
                    }
                    else
                    {
                        newElement.FileType = newElement.Name;
                    }
                }

                //set the icon
                string filename = "_tmp_ext" + newElement.Name.Split('.').Last();
                Windows.Storage.StorageFile iconHelperFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

                Windows.Storage.FileProperties.StorageItemThumbnail iconHelperThumbnail = await iconHelperFile.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem,
                                                                                                                                 16, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail);

                if (iconHelperThumbnail != null)
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(iconHelperThumbnail.CloneStream());
                    newElement.Icon = bitmapImage;
                }

                files.Add(newElement);
            }

            return(files);
        }
Ejemplo n.º 5
0
        public static async Task <List <IOElement> > ParseLinuxFiles(string rawList, string path)
        {
            List <IOElement> files = new List <IOElement>();

            foreach (string item in rawList.Trim().Split('\n'))
            {
                IOElement newElement = new IOElement();

                string trimmedItem = item.Trim();

                string tmp = trimmedItem.Substring(0, trimmedItem.IndexOf(' ')).Trim();

                trimmedItem = trimmedItem.Remove(0, trimmedItem.IndexOf(' '));

                newElement.IsFile = tmp.StartsWith("d") ? false : true;

                int ownerNumber  = 0;
                int groupNumber  = 0;
                int publicNumber = 0;

                if (tmp[1] == 'r')
                {
                    ownerNumber += 4;
                }
                if (tmp[2] == 'w')
                {
                    ownerNumber += 2;
                }
                if (tmp[3] == 'x')
                {
                    ownerNumber += 1;
                }

                if (tmp[4] == 'r')
                {
                    groupNumber += 4;
                }
                if (tmp[5] == 'w')
                {
                    groupNumber += 2;
                }
                if (tmp[6] == 'x')
                {
                    groupNumber += 1;
                }

                if (tmp[7] == 'r')
                {
                    publicNumber += 4;
                }
                if (tmp[8] == 'w')
                {
                    publicNumber += 2;
                }
                if (tmp[9] == 'x')
                {
                    publicNumber += 1;
                }

                newElement.Rigths       = ownerNumber * 100 + groupNumber * 10 + publicNumber;
                newElement.RigthsString = newElement.Rigths.ToString();

                trimmedItem = trimmedItem.Trim();

                string trash = trimmedItem.Substring(0, trimmedItem.IndexOf(' '));
                trimmedItem      = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.Owner = trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem      = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.Group = trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem     = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.Size = ulong.Parse(trimmedItem.Substring(0, trimmedItem.IndexOf(' ')));

                trimmedItem         = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.LastEdit = trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem          = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.LastEdit += "." + trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem          = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();
                newElement.LastEdit += "." + trimmedItem.Substring(0, trimmedItem.IndexOf(' '));

                trimmedItem = trimmedItem.Remove(0, trimmedItem.IndexOf(' ')).Trim();

                newElement.Name = trimmedItem;

                newElement.Path = path;

                //skip those entries
                if (newElement.Name == "." || newElement.Name == "..")
                {
                    continue;
                }

                if (newElement.IsFile == false)
                {
                    newElement.FileType = "Directory";
                }
                else
                {
                    if (newElement.Name.Contains("."))
                    {
                        newElement.FileType = newElement.Name.Substring(newElement.Name.LastIndexOf('.'));
                    }
                    else
                    {
                        newElement.FileType = newElement.Name;
                    }
                }

                //set the icon
                if (newElement.IsFile)
                {
                    string filename = "_tmp_ext" + "." + newElement.Name.Split('.').Last();
                    Windows.Storage.StorageFile iconHelperFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

                    Windows.Storage.FileProperties.StorageItemThumbnail iconHelperThumbnail = await iconHelperFile.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem,
                                                                                                                                     64, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail);

                    if (iconHelperThumbnail != null)
                    {
                        try
                        {
                            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                BitmapImage bitmapImage = new BitmapImage();
                                bitmapImage.SetSource(iconHelperThumbnail.CloneStream());
                                newElement.Icon = bitmapImage;
                            });
                        }
                        catch (Exception ex) { }
                    }
                }

                files.Add(newElement);
            }

            return(files);
        }
Ejemplo n.º 6
0
 private StorageItemThumbnail(Windows.Storage.FileProperties.StorageItemThumbnail thumbnail)
 {
     _thumbnail = thumbnail;
     _stream    = _thumbnail.AsStreamForRead();
 }