Skip to content

Commit

Permalink
Final v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-knuth committed Apr 30, 2021
1 parent 485dc6f commit 2d17352
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
16 changes: 10 additions & 6 deletions Scanner/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ await RunOnUIThreadAsync(CoreDispatcherPriority.Normal, async () =>
{
// first app launch after an update
log.Information("MainPage loaded after first launch with this version.");
//await RunOnUIThreadAsync(CoreDispatcherPriority.Normal, () => ReliablyOpenTeachingTip(TeachingTipUpdated));
await RunOnUIThreadAsync(CoreDispatcherPriority.Normal, () => ReliablyOpenTeachingTip(TeachingTipUpdated));
}

// initialize debug menu
Expand Down Expand Up @@ -932,6 +932,7 @@ await RunOnUIThreadAsync(CoreDispatcherPriority.High, () =>
Tuple<ImageScannerFormat, SupportedFormat?> selectedFormat;
ImageScannerScanSource scanSource;

bool askedForFolder = false;
if (settingSaveLocationAsk && ( scanResult == null || scanResult.GetFileFormat() != SupportedFormat.PDF))
{
// ask user for save location
Expand All @@ -948,6 +949,7 @@ await RunOnUIThreadAsync(CoreDispatcherPriority.High, () =>
await CancelScanAsync();
return false;
}
askedForFolder = true;
}
else scanFolderTemp = null;

Expand Down Expand Up @@ -1081,13 +1083,13 @@ await RunOnUIThreadAsync(CoreDispatcherPriority.Normal,
{
// no conversion
scanResult = await ScanResult.CreateAsync(scannerScanResult.ScannedFiles, folderToSaveTo, futureAccessListIndex,
settingSaveLocationAsk);
askedForFolder);
}
else
{
// conversion necessary
scanResult = await ScanResult.CreateAsync(scannerScanResult.ScannedFiles, folderToSaveTo,
(SupportedFormat)selectedFormat.Item2, futureAccessListIndex, settingSaveLocationAsk);
(SupportedFormat)selectedFormat.Item2, futureAccessListIndex, askedForFolder);
}

FlipViewScan.ItemsSource = scanResult.elements;
Expand Down Expand Up @@ -1142,11 +1144,11 @@ await RunOnUIThreadAsync(CoreDispatcherPriority.Normal, async () =>
if (ConvertFormatStringToSupportedFormat(copiedDebugFiles[0].FileType) != selectedDebugFormat)
{
scanResult = await ScanResult.CreateAsync(copiedDebugFiles, folderToSaveTo, selectedDebugFormat, futureAccessListIndex,
settingSaveLocationAsk);
askedForFolder);
}
else
{
scanResult = await ScanResult.CreateAsync(copiedDebugFiles, folderToSaveTo, futureAccessListIndex, settingSaveLocationAsk);
scanResult = await ScanResult.CreateAsync(copiedDebugFiles, folderToSaveTo, futureAccessListIndex, askedForFolder);
}
await RunOnUIThreadAsync(CoreDispatcherPriority.Normal, () =>
{
Expand Down Expand Up @@ -1612,7 +1614,9 @@ private void RefreshScanButton()
MenuFlyoutItemButtonScanFresh.FontWeight = FontWeights.Normal;
return;
}
else if (scanResult != null && scanResult.originalTargetFolder.Path != scanFolder.Path && !settingSaveLocationAsk)
else if (scanResult != null &&
((settingSaveLocationAsk && String.IsNullOrEmpty(scanResult.elements[0].DisplayedFolder)) || // switched from set location
(!settingSaveLocationAsk && scanResult.originalTargetFolder.Path != scanFolder.Path))) // switched to set location or changed location
{
// save location has changed
FontIconButtonScanAdd.Visibility = Visibility.Collapsed;
Expand Down
27 changes: 18 additions & 9 deletions Scanner/ScanResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ScanResult
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private ScanResult(IReadOnlyList<StorageFile> fileList, StorageFolder targetFolder, int futureAccessListIndexStart, bool displayFolder)
{
log.Information("ScanResult constructor [futureAccessListIndexStart={Index}|displayFolder={Folder}]", futureAccessListIndexStart, displayFolder);
int futureAccessListIndex = futureAccessListIndexStart;
foreach (StorageFile file in fileList)
{
Expand All @@ -51,7 +52,7 @@ private ScanResult(IReadOnlyList<StorageFile> fileList, StorageFolder targetFold
if (displayFolder) elements.Add(new ScanResultElement(file, futureAccessListIndex, targetFolder.DisplayName));
else elements.Add(new ScanResultElement(file, futureAccessListIndex, null));

StorageApplicationPermissions.FutureAccessList.AddOrReplace(futureAccessListIndex.ToString(), targetFolder);
StorageApplicationPermissions.FutureAccessList.AddOrReplace("Scan_" + futureAccessListIndex.ToString(), targetFolder);
futureAccessListIndex += 1;
}
scanResultFormat = (SupportedFormat)ConvertFormatStringToSupportedFormat(elements[0].ScanFile.FileType);
Expand Down Expand Up @@ -706,7 +707,7 @@ public async Task CropScanAsCopyAsync(int index, ImageCropper imageCropper)
{
StorageFolder folder = null;
if (scanResultFormat == SupportedFormat.PDF) folder = folderConversion;
else folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(elements[index].FutureAccessListIndex.ToString());
else folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("Scan_" + elements[index].FutureAccessListIndex.ToString());

file = await folder.CreateFileAsync(elements[index].ScanFile.Name, CreationCollisionOption.GenerateUniqueName);
stream = await file.OpenAsync(FileAccessMode.ReadWrite);
Expand Down Expand Up @@ -941,7 +942,7 @@ public async Task DrawOnScanAsCopyAsync(int index, InkCanvas inkCanvas)

StorageFolder folder = null;
if (scanResultFormat == SupportedFormat.PDF) folder = folderConversion;
else folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(elements[index].FutureAccessListIndex.ToString());
else folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("Scan_" + elements[index].FutureAccessListIndex.ToString());

file = await folder.CreateFileAsync(elements[index].ScanFile.Name, CreationCollisionOption.GenerateUniqueName);
using (IRandomAccessStream targetStream = await file.OpenAsync(FileAccessMode.ReadWrite))
Expand Down Expand Up @@ -1213,11 +1214,15 @@ public async Task AddFiles(IReadOnlyList<StorageFile> files, SupportedFormat? ta

foreach (StorageFile file in files)
{
if (displayFolder) elements.Add(new ScanResultElement(file, futureAccessListIndex, targetFolder.DisplayName));
if (displayFolder && targetFolder != null) elements.Add(new ScanResultElement(file, futureAccessListIndex, targetFolder.DisplayName));
else elements.Add(new ScanResultElement(file, futureAccessListIndex, null));

futureAccessListIndex += 1;
StorageApplicationPermissions.FutureAccessList.AddOrReplace(futureAccessListIndex.ToString(), targetFolder);
if (targetFolder != null)
{
StorageApplicationPermissions.FutureAccessList.AddOrReplace("Scan_" + futureAccessListIndex.ToString(), targetFolder);
futureAccessListIndex += 1;
}

if (settingAppendTime && targetFormat != SupportedFormat.PDF) await SetInitialNameAsync(elements[elements.Count - 1], append);
}
}
Expand All @@ -1230,11 +1235,15 @@ public async Task AddFiles(IReadOnlyList<StorageFile> files, SupportedFormat? ta
{
if (file == null) continue;

if (displayFolder) elements.Add(new ScanResultElement(file, futureAccessListIndex, targetFolder.DisplayName));
if (displayFolder && targetFolder != null) elements.Add(new ScanResultElement(file, futureAccessListIndex, targetFolder.DisplayName));
else elements.Add(new ScanResultElement(file, futureAccessListIndex, null));

StorageApplicationPermissions.FutureAccessList.AddOrReplace(futureAccessListIndex.ToString(), targetFolder);
futureAccessListIndex += 1;
if (targetFolder != null)
{
StorageApplicationPermissions.FutureAccessList.AddOrReplace("Scan_" + futureAccessListIndex.ToString(), targetFolder);
futureAccessListIndex += 1;
}

if (settingAppendTime) await SetInitialNameAsync(elements[elements.Count - 1], append);
}

Expand Down

0 comments on commit 2d17352

Please sign in to comment.