Пример #1
0
 public void Add(StorageFile file)
 {
     if (!_future.Entries.Any(x => x.Metadata.Equals(file.Path)))
     {
         _future.Add(file, file.Path);
     }
 }
    public async Task <bool> NewAsync()
    {
        StorageFile file = await SaveFileAsync(desc_archive, extension_zip, desc_archive);

        if (file != null)
        {
            _token = _access.Add(file);
            Name   = file.Name;
            using (Stream stream = await file.OpenStreamForWriteAsync())
            {
                new ZipArchive(stream, ZipArchiveMode.Create);
            }
            return(true);
        }
        return(false);
    }
Пример #3
0
        private async void AddPicturesButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            FileOpenPicker filePicker = new FileOpenPicker {
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };

            filePicker.FileTypeFilter.Add(".jpg");
            filePicker.FileTypeFilter.Add(".jpeg");
            filePicker.FileTypeFilter.Add(".png");
            filePicker.FileTypeFilter.Add(".bmp");
            filePicker.FileTypeFilter.Add(".gif");
            filePicker.FileTypeFilter.Add(".tiff");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file = await filePicker.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    StorageItemAccessList storageItemAccessList = StorageApplicationPermissions.FutureAccessList;
                    storageItemAccessList.Add(file);


                    //新建媒体
                    Media media = new Media();

                    //缩略图
                    using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.PicturesView))
                    {
                        if (thumbnail != null)
                        {
                            BitmapImage bitmapImage = new BitmapImage();
                            bitmapImage.SetSource(thumbnail);

                            media.Bitmap = bitmapImage;
                        }
                    }

                    //从文件创建媒体剪辑
                    MediaClip clip = await MediaClip.CreateFromImageFileAsync(file, new TimeSpan(24, 1, 0));

                    clip.TrimTimeFromEnd = clip.TrimTimeFromStart = new TimeSpan(12, 0, 0);
                    media.Clip           = clip;

                    //从颜色创建名称
                    media.Name = file.Name;

                    MediaClipList.Add(media);
                    SplitShowMethod();// SplitView:侧栏
                }
                catch (Exception)
                {
                    App.Tip("file err");
                }
            }
            else
            {
                App.Tip("file null");
            }
        }
Пример #4
0
        /// <summary>
        /// This function is called when the user clicks the Open button,
        /// and when they save (to refresh the image state).
        /// </summary>
        private async Task DisplayImageFileAsync(StorageFile file)
        {
            // Request persisted access permissions to the file the user selected.
            // This allows the app to directly load the file in the future without relying on a
            // broker such as the file picker.
            m_fileToken = m_futureAccess.Add(file);

            // Display the image in the UI.
            BitmapImage src = new BitmapImage();

            src.SetSource(await file.OpenAsync(FileAccessMode.Read));
            Image1.Source = src;
            AutomationProperties.SetName(Image1, file.Name);

            // Use BitmapDecoder to attempt to read EXIF orientation and image dimensions.
            await GetImageInformationAsync(file);

            ExifOrientationTextblock.Text = Helpers.GetOrientationString(m_exifOrientation);
            UpdateImageDimensionsUI();

            ScaleSlider.IsEnabled       = true;
            RotateLeftButton.IsEnabled  = true;
            RotateRightButton.IsEnabled = true;
            SaveButton.IsEnabled        = true;
            SaveAsButton.IsEnabled      = true;
            CloseButton.IsEnabled       = true;
        }
        private async void ChooseFile_Click(object sender, RoutedEventArgs e)
        {
            // Get file
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
            picker.FileTypeFilter.Add(".mp4");
            pickedFile = await picker.PickSingleFileAsync();

            if (pickedFile == null)
            {
                rootPage.NotifyUser("File picking cancelled", NotifyType.ErrorMessage);
                return;
            }

            // These files could be picked from a location that we won't have access to later
            // (especially if persisting the MediaComposition to disk and loading it later).
            // Use the StorageItemAccessList in order to keep access permissions to that
            // file for later use. Be aware that this access list needs to be cleared
            // periodically or the app will run out of entries.
            storageItemAccessList.Add(pickedFile);

            mediaElement.SetSource(await pickedFile.OpenReadAsync(), pickedFile.ContentType);
            trimClip.IsEnabled = true;
        }
Пример #6
0
        private async Task AddBackgroundAudioTrack()
        {
            var picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            picker.FileTypeFilter.Add(".mp3");
            picker.FileTypeFilter.Add(".wav");
            picker.FileTypeFilter.Add(".flac");
            StorageFile audioFile = await picker.PickSingleFileAsync();

            if (audioFile != null)
            {
                StorageItemAccessList storageItemAccessList = StorageApplicationPermissions.FutureAccessList;
                storageItemAccessList.Add(audioFile);

                BackgroundAudioTrack backgroundTrack = await BackgroundAudioTrack.CreateFromFileAsync(audioFile);

                App.Model.MediaComposition.BackgroundAudioTracks.Add(backgroundTrack);

                //裁剪,防止播出
                if (backgroundTrack.TrimmedDuration > App.Model.MediaComposition.Duration)
                {
                    backgroundTrack.Delay           = TimeSpan.Zero;
                    backgroundTrack.TrimTimeFromEnd = App.Model.MediaComposition.Duration - backgroundTrack.TrimmedDuration;
                }
            }
            else
            {
                App.Tip("File picking cancelled");
            }
        }
        /// <summary>
        /// This function is called when the user clicks the Open button,
        /// and when they save (to refresh the image state).
        /// </summary>
        private async Task DisplayImageFileAsync(StorageFile file)
        {
            // Request persisted access permissions to the file the user selected.
            // This allows the app to directly load the file in the future without relying on a
            // broker such as the file picker.
            m_fileToken = m_futureAccess.Add(file);

            // Display the image in the UI.
            BitmapImage src = new BitmapImage();

            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
            {
                await src.SetSourceAsync(stream);

                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                PlaceImage(decoder);
            }

            PreviewImage.Source = src;
            AutomationProperties.SetName(PreviewImage, file.Name);

            // Use BitmapDecoder to attempt to read EXIF orientation and image dimensions.
            await GetImageInformationAsync(file);
        }
Пример #8
0
        private static async Task <StorageFolder> PickFolder()
        {
            FolderPicker picker = new FolderPicker();

            picker.FileTypeFilter.Add(".");
            StorageFolder picked = await picker.PickSingleFolderAsync();

            Fal.Clear();
            Fal.Add(picked);
            return(picked);
        }
Пример #9
0
        protected override void SaveState(Dictionary <string, object> pageState)
        {
            MediaPlayerState      state  = MediaPlayer.GetPlayerState();
            StorageItemAccessList future = StorageApplicationPermissions.FutureAccessList;

            future.Clear();
            string token = future.Add(file);

            pageState.Add("MediaState", state);
            pageState.Add("fileToken", token);
            base.SaveState(pageState);
            if (teardown)
            {
                MediaPlayer.Dispose();
            }
        }
Пример #10
0
        public static string Enqueue(this StorageItemAccessList list, IStorageItem item)
        {
            if (list.MaximumItemsAllowed - 10 >= list.Entries.Count)
            {
                var first = list.Entries.FirstOrDefault();
                var token = first.Token;

                list.Remove(token);
            }

            try
            {
                return(list.Add(item));
            }
            catch
            {
                return(null);
            }
        }
Пример #11
0
        private async void ChooseFolderButton_TappedAsync(object sender, TappedRoutedEventArgs e)
        {
            FolderPicker folderPicker = new FolderPicker
            {
                SuggestedStartLocation = PickerLocationId.Desktop
            };

            folderPicker.FileTypeFilter.Add("*");

            StorageFolder selectedFolder = await folderPicker.PickSingleFolderAsync();

            if (selectedFolder != null)
            {
                // Save folder in MRU.
                string futureAccessToken = futureAccessList.Add(selectedFolder);
                localSettings.Values["PerformerImageFolder"] = futureAccessToken;
                PerformerImageFolderName.Text = selectedFolder.Path;
            }
        }
Пример #12
0
        /// <summary>
        /// Load an image from disk and display some basic imaging properties. Invoked
        /// when the user clicks on the Open button.
        /// </summary>
        private async void Open_Click(object sender, RoutedEventArgs e)
        {
            ResetSessionState();
            ResetPersistedState();

            try
            {
                rootPage.NotifyUser("Opening image file...", NotifyType.StatusMessage);

                StorageFile file = await Helpers.GetFileFromOpenPickerAsync();

                // Request persisted access permissions to the file the user selected.
                // This allows the app to directly load the file in the future without relying on a
                // broker such as the file picker.
                m_fileToken = m_futureAccess.Add(file);

                // Windows.Storage.FileProperties.ImageProperties provides convenience access to
                // commonly-used properties such as geolocation and keywords. It also accepts
                // queries for Windows property system keys such as "System.Photo.Aperture".
                m_imageProperties = await file.Properties.GetImagePropertiesAsync();

                string[] requests =
                {
                    "System.Photo.ExposureTime",        // In seconds
                    "System.Photo.FNumber"              // F-stop values defined by EXIF spec
                };

                IDictionary <string, object> retrievedProps = await m_imageProperties.RetrievePropertiesAsync(requests);
                await DisplayImageUIAsync(file, GetImagePropertiesForDisplay(retrievedProps));

                rootPage.NotifyUser("Loaded file from picker: " + file.Name, NotifyType.StatusMessage);
                CloseButton.IsEnabled = true;
                ApplyButton.IsEnabled = true;
            }
            catch (Exception err)
            {
                rootPage.NotifyUser("Error: " + err.Message, NotifyType.ErrorMessage);
                ResetPersistedState();
                ResetSessionState();
            }
        }
Пример #13
0
        /// <summary>
        ///     Records a file transfer for future resuming between core restarts.
        /// </summary>
        /// <param name="file">The file associated with the transfer.</param>
        /// <param name="friendNumber">The friend number of the transfer.</param>
        /// <param name="fileNumber">The file number of the transfer.</param>
        /// <param name="direction">The direction of the transfer.</param>
        public void RecordTransfer(StorageFile file, int friendNumber, int fileNumber, TransferDirection direction)
        {
            // TODO: Maybe we should try to make place for newer items?
            if (_futureAccesList.MaximumItemsAllowed == _futureAccesList.Entries.Count)
            {
                return;
            }

            var metadata = new TransferMetadata
            {
                FriendNumber     = friendNumber,
                FileNumber       = fileNumber,
                FileId           = _toxModel.FileGetId(friendNumber, fileNumber),
                TransferredBytes = 0,
                Direction        = direction
            };

            var xmlMetadata = SerializeMetadata(metadata);

            _futureAccesList.Add(file, xmlMetadata);
        }
Пример #14
0
        public static string Enqueue(this StorageItemAccessList list, IStorageItem item)
        {
            try
            {
                if (list.Entries.Count >= list.MaximumItemsAllowed - 10)
                {
                    var first = list.Entries.LastOrDefault();
                    if (first.Token != null)
                    {
                        list.Remove(first.Token);
                    }
                }
            }
            catch { }

            try
            {
                return(list.Add(item));
            }
            catch
            {
                return(null);
            }
        }
Пример #15
0
        private async void AddMusicButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            FileOpenPicker filePicker = new FileOpenPicker {
                SuggestedStartLocation = PickerLocationId.MusicLibrary
            };

            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wma");
            filePicker.FileTypeFilter.Add(".wav");

            filePicker.FileTypeFilter.Add(".asf");  //微软的格式
            filePicker.FileTypeFilter.Add(".ogg");  //开源的格式
            filePicker.FileTypeFilter.Add(".flac"); //开源的格式
            filePicker.FileTypeFilter.Add(".aac");

            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file = await filePicker.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    StorageItemAccessList storageItemAccessList = StorageApplicationPermissions.FutureAccessList;
                    storageItemAccessList.Add(file);


                    //新建媒体
                    Media media = new Media();

                    //缩略图
                    using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.MusicView))
                    {
                        if (thumbnail != null)
                        {
                            BitmapImage bitmapImage = new BitmapImage();
                            bitmapImage.SetSource(thumbnail);

                            media.Bitmap = bitmapImage;
                        }
                    }

                    //从文件创建媒体剪辑
                    MediaClip clip = await MediaClip.CreateFromFileAsync(file);

                    media.Clip = clip;

                    //从颜色创建名称
                    media.Name = file.Name;

                    MediaClipList.Add(media);
                    SplitShowMethod();// SplitView:侧栏
                }
                catch (Exception)
                {
                    App.Tip("file err");
                }
            }
            else
            {
                App.Tip("file null");
            }
        }
Пример #16
0
        /// <summary>
        /// Registers the specified storage file.
        /// </summary>
        /// <param name="file">The database file.</param>
        /// <returns>The database registration information.</returns>
        public async Task <DatabaseRegistration> RegisterAsync(IStorageFile file)
        {
            using (var input = await file.OpenReadAsync())
            {
                var headers = await FileFormat.Headers(input);

                switch (headers.Format)
                {
                case FileFormats.KeePass1x:
                case FileFormats.NewVersion:
                case FileFormats.NotSupported:
                case FileFormats.OldVersion:
                    await _events.PublishOnUIThreadAsync(
                        new DatabaseSupportMessage
                    {
                        FileName = file.Name,
                        Format   = headers.Format,
                    });

                    return(null);

                case FileFormats.PartialSupported:
                    await _events.PublishOnUIThreadAsync(
                        new DatabaseSupportMessage
                    {
                        FileName = file.Name,
                        Format   = headers.Format,
                    });

                    break;
                }
            }

            var meta = new DatabaseMetaData
            {
                Name = GetName(file.Name),
            };

            // Check already registered database file
            var exists = _accessList.CheckAccess(file);

            if (exists)
            {
                await _events.PublishOnUIThreadAsync(
                    new DuplicateDatabaseMessage());

                return(null);
            }

            // Register for future access
            var token = _accessList.Add(file,
                                        JsonConvert.SerializeObject(meta));
            await file.CopyAsync(await _cacheFolder, token + ".kdbx");

            var info = new DatabaseRegistration
            {
                Id   = token,
                Name = meta.Name,
            };

            // Send notification message
            await _events.PublishOnUIThreadAsync(
                new DatabaseRegistrationMessage
            {
                Id           = info.Id,
                Registration = info,
                Action       = DatabaseRegistrationActions.Added,
            });

            return(info);
        }