예제 #1
0
        // 通过 StorageFolder.Properties 的 RetrievePropertiesAsync() 方法获取文件的属性
        private async Task ShowProperties3(StorageFile storageFile)
        {
            /*
             * 获取文件的其它各种属性
             * 详细的属性列表请参见结尾处的“附录一: 属性列表”或者参见:http://msdn.microsoft.com/en-us/library/windows/desktop/ff521735(v=vs.85).aspx
             */
            List <string> propertiesName = new List <string>();

            propertiesName.Add("System.DateAccessed");
            propertiesName.Add("System.DateCreated");
            propertiesName.Add("System.FileOwner");
            propertiesName.Add("System.FileAttributes");

            StorageItemContentProperties storageItemContentProperties = storageFile.Properties;
            IDictionary <string, object> extraProperties = await storageItemContentProperties.RetrievePropertiesAsync(propertiesName);

            lblMsg.Text += "System.DateAccessed:" + extraProperties["System.DateAccessed"];
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "System.DateCreated:" + extraProperties["System.DateCreated"];
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "System.FileOwner:" + extraProperties["System.FileOwner"];
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "System.FileAttributes:" + extraProperties["System.FileAttributes"];
            lblMsg.Text += Environment.NewLine;
        }
        private async Task LoadFile(StorageFile file)
        {
            if (isCanceled)
            {
                return;
            }

            if (Utilities.IsSupportedFileType(file.FileType))
            {
                StorageItemContentProperties fileProperties = file.Properties;

                MusicProperties musicProperties = await fileProperties.GetMusicPropertiesAsync();

                IDictionary <string, object> artistProperties = await fileProperties.RetrievePropertiesAsync(RealMusicProperties);

                object artists = null;
                artistProperties.TryGetValue("System.Music.Artist", out artists);

                string[] artistsAsArray = DebugHelper.CastAndAssert <string[]>(artists);

                string artistName = string.Empty;

                if (artistsAsArray != null && artistsAsArray.Length > 0)
                {
                    artistName = artistsAsArray[0];
                }

                if (this.TrackScanned != null)
                {
                    this.TrackScanned(this, new TrackScannedEventArgs(new StorageProviderSong(file.Path, musicProperties, artistName)));
                }
            }
        }
예제 #3
0
        private async Task <Dictionary <string, string> > GetProperties(StorageFile temporaryFile, CancellationToken cancellationToken)
        {
            StorageItemContentProperties properties = temporaryFile.Properties;
            MusicProperties musicProperties         = await properties.GetMusicPropertiesAsync();

            VideoProperties videoProperties = await properties.GetVideoPropertiesAsync();

            BasicProperties basicProperties = await temporaryFile.GetBasicPropertiesAsync();

            CancelTask(cancellationToken);

            Dictionary <string, string> tempDictionary = new Dictionary <string, string>();

            tempDictionary["Display Name"]        = temporaryFile.DisplayName;
            tempDictionary["File Type"]           = temporaryFile.FileType;
            tempDictionary["Current Folder Path"] = temporaryFile.FolderRelativeId;
            tempDictionary["Size"]           = string.Format("{0:0.00}", (Convert.ToDouble(basicProperties.Size) / 1048576d)) + " Mb";
            tempDictionary["Creation Date"]  = temporaryFile.DateCreated.ToString();
            tempDictionary["Modified Date"]  = basicProperties.DateModified.ToString();
            tempDictionary["Audio Bit Rate"] = musicProperties.Bitrate + " bps";
            tempDictionary["Length"]         = videoProperties.Duration.ToString("hh\\:mm\\:ss");
            tempDictionary["Frame Width"]    = videoProperties.Width + "";
            tempDictionary["Frame Height"]   = videoProperties.Height + "";
            tempDictionary["Orientation"]    = videoProperties.Orientation + "";
            tempDictionary["Total Bit Rate"] = videoProperties.Bitrate + " bps";

            CancelTask(cancellationToken);

            return(tempDictionary);
        }
예제 #4
0
        public async void GetOtherPropeties(StorageItemContentProperties properties)
        {
            string        dateAccessedProperty = "System.DateAccessed";
            string        fileOwnerProperty    = "System.FileOwner";
            List <string> propertiesName       = new List <string>();

            propertiesName.Add(dateAccessedProperty);
            propertiesName.Add(fileOwnerProperty);
            IDictionary <string, object> extraProperties = await properties.RetrievePropertiesAsync(propertiesName);

            ViewModel.ItemAccessedTimestamp = ListedItem.GetFriendlyDate((DateTimeOffset)extraProperties[dateAccessedProperty]);
            ViewModel.ItemFileOwner         = extraProperties[fileOwnerProperty].ToString();
        }
예제 #5
0
        public async void GetOtherProperties(StorageItemContentProperties properties)
        {
            string        dateAccessedProperty = "System.DateAccessed";
            List <string> propertiesName       = new List <string>();

            propertiesName.Add(dateAccessedProperty);
            IDictionary <string, object> extraProperties = await properties.RetrievePropertiesAsync(propertiesName);

            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
            string returnformat = Enum.Parse <TimeStyle>(localSettings.Values[Constants.LocalSettings.DateTimeFormat].ToString()) == TimeStyle.Application ? "D" : "g";

            // Cannot get date and owner in MTP devices
            ViewModel.ItemAccessedTimestamp = ((DateTimeOffset)(extraProperties[dateAccessedProperty] ?? DateTimeOffset.Now)).GetFriendlyDateFromFormat(returnformat);
        }
예제 #6
0
        private async void Rename(Tag mytag)
        {
            CurrentSong = SongList.SelectedItem as Song;

            using (SQLiteConnection db = new SQLiteConnection(App.DB_PATH))
            {
                string import_name;
                var    temp_format_id = db.Find <MusicFormat>(c => c.Id == CurrentSong.FormatId);
                import_name = CurrentSong.Path + CurrentSong.NameSong + "." + temp_format_id.NameFormat;

                Main_folder = await Windows.Storage.AccessCache.StorageApplicationPermissions
                              .FutureAccessList.GetFolderAsync("Audio");

                StorageFile music_files = await Main_folder.GetFileAsync(import_name);

                var fileProperties = await music_files.Properties.GetMusicPropertiesAsync();

                //*Нормально не изменяет артиста
                StorageItemContentProperties rfileProperties = music_files.Properties;
                MusicProperties musicFileProperties          = await rfileProperties.GetMusicPropertiesAsync();

                string[] contributingArtistsKey = { "System.Music.Artist" };
                IDictionary <string, object> contributingArtistsProperty =
                    await musicFileProperties.RetrievePropertiesAsync(contributingArtistsKey);

                string[] contributingArtists = contributingArtistsProperty["System.Music.Artist"] as string[];

                //fileProperties.Genre = mytag.Genge; \\только для чтения
                fileProperties.TrackNumber = Convert.ToUInt32(mytag.TrackNumber);
                fileProperties.Album       = mytag.Albom;
                fileProperties.Artist      = mytag.Artist;
                //fileProperties.Composers = mytag.Composer; \\только для чтения
                fileProperties.Title       = mytag.NameSong;
                fileProperties.Year        = Convert.ToUInt32(mytag.Year);
                fileProperties.AlbumArtist = mytag.ArtistAlbom;
                //*Ошибка доступа для Флер
                await fileProperties.SavePropertiesAsync();

                var temp_song = db.Find <Song>(c => c.TagId == mytag.Id);
                await Task.Run(() =>
                {
                    temp_song.DateChange = DateTime.Now.AddHours(5);
                    Db_Helper.Update_Song(temp_song);
                });
            }
            var dialog = new MessageDialog("Тег изменен");
            await dialog.ShowAsync();
        }
예제 #7
0
        // 通过 StorageFolder.Properties 的 GetImagePropertiesAsync(), GetVideoPropertiesAsync(), GetMusicPropertiesAsync(), GetDocumentPropertiesAsync() 方法获取文件的属性
        private async Task ShowProperties4(StorageFile storageFile)
        {
            StorageItemContentProperties storageItemContentProperties = storageFile.Properties;
            ImageProperties imageProperties = await storageItemContentProperties.GetImagePropertiesAsync();          // 图片属性

            VideoProperties videoProperties = await storageItemContentProperties.GetVideoPropertiesAsync();          // 视频属性

            MusicProperties musicProperties = await storageItemContentProperties.GetMusicPropertiesAsync();          // 音频属性

            DocumentProperties documentProperties = await storageItemContentProperties.GetDocumentPropertiesAsync(); // 文档属性

            lblMsg.Text += "image width:" + imageProperties.Width;
            lblMsg.Text += Environment.NewLine;
            lblMsg.Text += "image height:" + imageProperties.Height;
            lblMsg.Text += Environment.NewLine;
        }
예제 #8
0
        public async void GetOtherProperties(StorageItemContentProperties properties)
        {
            string        dateAccessedProperty = "System.DateAccessed";
            string        fileOwnerProperty    = "System.FileOwner";
            List <string> propertiesName       = new List <string>();

            propertiesName.Add(dateAccessedProperty);
            propertiesName.Add(fileOwnerProperty);
            IDictionary <string, object> extraProperties = await properties.RetrievePropertiesAsync(propertiesName);

            // Cannot get date and owner in MTP devices
            ViewModel.ItemAccessedTimestamp = ListedItem.GetFriendlyDate((DateTimeOffset)(extraProperties[dateAccessedProperty] ?? DateTimeOffset.Now));

            if (App.AppSettings.ShowFileOwner)
            {
                // Cannot get date and owner in MTP devices
                ViewModel.ItemFileOwner = extraProperties[fileOwnerProperty]?.ToString();
            }
        }
예제 #9
0
        // 修改文件的属性
        private async void btnModifyProperty_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // 用户选中的文件
            string        fileName       = (string)listBox.SelectedItem;
            StorageFolder picturesFolder = await KnownFolders.GetFolderForUserAsync(null, KnownFolderId.PicturesLibrary);

            StorageFile storageFile = await picturesFolder.GetFileAsync(fileName);

            // 在 System.FileAttributes 中保存有文件是否是“只读”的信息
            string[] retrieveList = new string[] { "System.FileAttributes" };
            StorageItemContentProperties storageItemContentProperties = storageFile.Properties;
            IDictionary <string, object> extraProperties = await storageItemContentProperties.RetrievePropertiesAsync(retrieveList);

            uint FILE_ATTRIBUTES_READONLY = 1;

            if (extraProperties != null && extraProperties.ContainsKey("System.FileAttributes"))
            {
                // 切换文件的只读属性
                uint temp = (UInt32)extraProperties["System.FileAttributes"] ^ FILE_ATTRIBUTES_READONLY;

                // 设置文件的只读属性为 true
                // uint temp = (UInt32)extraProperties["System.FileAttributes"] | 1;

                // 设置文件的只读属性为 false
                // uint temp = (UInt32)extraProperties["System.FileAttributes"] & 0;

                extraProperties["System.FileAttributes"] = temp;
            }
            else
            {
                // 设置文件的只读属性为 true
                extraProperties = new PropertySet();
                extraProperties.Add("System.FileAttributes", FILE_ATTRIBUTES_READONLY);
            }

            // 保存修改后的属性(用这种方法可以修改部分属性,大部分属性都是无权限修改的)
            await storageFile.Properties.SavePropertiesAsync(extraProperties);
        }