private void CheckInitValues() { if (SubFolderDataIn == "" || SubFolderDataIn == "." || SubFolderDataIn == "/" || SubFolderDataIn == "./" || SubFolderDataOut == "" || SubFolderDataOut == "." || SubFolderDataOut == "/" || SubFolderDataOut == "./" || SubFolderDataIn == SubFolderDataOut) { throw new ApplicationException($"Wrong hardcoded paths for {AlgCode}, DataIn/Out can't be the same folder as EnvPath or each other."); } if (!EnvPath.EndsWith("/") || !SubFolderDataIn.EndsWith("/") || !SubFolderDataOut.EndsWith("/")) { throw new ApplicationException("Violation of folder name convention. Folder names should have a trailing forward slash."); } }
public static async Task <BitmapImage> CreateBitmapFromArchiveCover(string path, int thumWidth) { StorageFolder folder = await EnvPath.GetArchiveCoverFolder(); string fileName = EnvPath.GetArchiveCoverFileName(path); IStorageItem imageFile = await folder.TryGetItemAsync(fileName); if (imageFile == null) { using (await m_asyncLock.LockAsync()) { StorageFile coverFile = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); StorageFile zipFile = await StorageFile.GetFileFromPathAsync(path); using (IRandomAccessStream randomStream = await zipFile.OpenReadAsync()) { using (Stream stream = randomStream.AsStreamForRead()) { using (ZipArchive zipArchive = new ZipArchive(stream)) { foreach (ZipArchiveEntry entry in zipArchive.Entries) { if (FileKind.IsImageFile(entry.FullName)) { /* * WriteableBitmap writeableBitmap = await createWriteableBitmap(entry); * await saveToJpegFile(writeableBitmap, coverFile); * imageFile = await folder.GetFileAsync(fileName); */ imageFile = await SaveToFileFromZipEntry(entry, coverFile); break; } } } } } } } if (imageFile != null) { return(await CreateThumbnailBitmap(imageFile, (uint)thumWidth)); } else { return(null); } }
/// <summary> /// カテゴリの追加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void addButton_Click(object sender, RoutedEventArgs e) { InsertScrapbookDialog dialog = new InsertScrapbookDialog(); await dialog.ShowAsync(); if (!string.IsNullOrEmpty(dialog.FolderName)) { ScrapbookCategory category = new ScrapbookCategory() { FolderName = dialog.FolderName, }; if (EnvPath.GetScrapbookSubFolder(category.FolderName) != null) { m_db.InsertScrapbookCategory(category); } } }
/// <summary> /// 指定したカテゴリに登録するためのスクラップブックを作成しオブジェクトを返す /// </summary> /// <param name="category"></param> /// <returns></returns> public async Task <ScrapbookItem> CreateScrapbookItem(ScrapbookCategory category) { string fileName = EnvPath.CreateScrapbookFileName(); StorageFolder folder = await EnvPath.GetScrapbookSubFolder(category.FolderName); StorageFile copyFile = await m_reader.CopyFileAsync(this.SelectedIndex, folder, fileName); if (copyFile == null) { return(null); } return(new ScrapbookItem() { ScrapbookCategoryId = category.Id, FileName = Path.GetFileName(copyFile.Path), Uptime = DateTime.Now }); }