6 Commits

8 changed files with 120 additions and 11 deletions

View File

@@ -327,6 +327,9 @@ public partial class ImportRoms : ComponentBase
if(!archiveImporter.IsCrcInDb(reader.Entry.Crc) && KnownOnlyChecked) continue;
// Do not import files that are already in the repository
if(archiveImporter.IsInRepo(reader.Entry.Crc)) continue;
var worker = new FileImporter(_ctx,
_newFiles,
_newDisks,
@@ -342,10 +345,24 @@ public partial class ImportRoms : ComponentBase
tmpFile,
reader.Entry.Size);
if(File.Exists(tmpFile)) File.Delete(tmpFile);
try
{
if(File.Exists(tmpFile)) File.Delete(tmpFile);
}
catch(IOException)
#pragma warning disable PH2098
{
// Ignore IO exceptions when deleting temporary files
}
#pragma warning restore PH2098
}
}
catch(InvalidOperationException) {}
#pragma warning disable RCS1075, PH2098, ERP022
catch(Exception)
{
// Show must go on
}
#pragma warning restore RCS1075, PH2098, ERP022
finally
{
Interlocked.Increment(ref _listPosition);

View File

@@ -556,6 +556,14 @@ public sealed class FileImporter
}
}
public bool IsInRepo(long crc32)
{
lock(DbLock)
{
return _ctx.Files.Any(f => f.Crc32 == crc32.ToString("x8") && f.IsInRepo);
}
}
public void ImportAndHashRom(Stream stream, string filename, string tempPath, long size)
{
try

View File

@@ -65,6 +65,7 @@ internal static class Program
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<App>()
.UsePlatformDetect()
#if DEBUG
.LogToSerilog(LogEventLevel.Debug);
#else

View File

@@ -788,5 +788,23 @@ namespace RomRepoMgr.Resources {
return ResourceManager.GetString("ProcessingArchive", resourceCulture);
}
}
public static string ErrorProcessingArchive {
get {
return ResourceManager.GetString("ErrorProcessingArchive", resourceCulture);
}
}
public static string UnknownFile {
get {
return ResourceManager.GetString("UnknownFile", resourceCulture);
}
}
public static string FileAlreadyInRepository {
get {
return ResourceManager.GetString("FileAlreadyInRepository", resourceCulture);
}
}
}
}

View File

@@ -390,4 +390,13 @@ Tardará mucho tiempo...</value>
<data name="ProcessingArchive" xml:space="preserve">
<value>Procesando archivo: {0}</value>
</data>
<data name="ErrorProcessingArchive" xml:space="preserve">
<value>Error procesando archivo.</value>
</data>
<data name="UnknownFile" xml:space="preserve">
<value>Fichero desconocido.</value>
</data>
<data name="FileAlreadyInRepository" xml:space="preserve">
<value>Fichero ya en el repositorio.</value>
</data>
</root>

View File

@@ -398,4 +398,13 @@ This will take a long time...</value>
<data name="ProcessingArchive" xml:space="preserve">
<value>Processing archive: {0}</value>
</data>
<data name="ErrorProcessingArchive" xml:space="preserve">
<value>Error processing archive.</value>
</data>
<data name="UnknownFile" xml:space="preserve">
<value>Unknown file.</value>
</data>
<data name="FileAlreadyInRepository" xml:space="preserve">
<value>File already in repository.</value>
</data>
</root>

View File

@@ -404,11 +404,41 @@ public sealed partial class ImportRomFolderViewModel : ViewModelBase
// Process files in archive
while(reader.MoveToNextEntry())
{
string filename = Path.GetFileName(reader.Entry.Key);
if(reader.Entry.IsDirectory) continue;
if(reader.Entry.Crc == 0 && KnownOnlyChecked) continue;
if(reader.Entry.Crc == 0 && KnownOnlyChecked ||
!archiveImporter.IsCrcInDb(reader.Entry.Crc) && KnownOnlyChecked)
{
Dispatcher.UIThread.Post(() => Importers.Add(new RomImporter
{
Filename = filename,
Indeterminate = false,
Progress = 1,
Maximum = 1,
Minimum = 0,
StatusMessage = Localization.UnknownFile
}));
if(!archiveImporter.IsCrcInDb(reader.Entry.Crc) && KnownOnlyChecked) continue;
continue;
}
// Do not import files that are already in the repository
if(archiveImporter.IsInRepo(reader.Entry.Crc))
{
Dispatcher.UIThread.Post(() => Importers.Add(new RomImporter
{
Filename = filename,
Indeterminate = false,
Progress = 1,
Maximum = 1,
Minimum = 0,
StatusMessage = Localization.FileAlreadyInRepository
}));
continue;
}
var model = new RomImporter
{
@@ -440,10 +470,32 @@ public sealed partial class ImportRomFolderViewModel : ViewModelBase
tmpFile,
reader.Entry.Size);
if(File.Exists(tmpFile)) File.Delete(tmpFile);
try
{
if(File.Exists(tmpFile)) File.Delete(tmpFile);
}
catch(IOException)
#pragma warning disable PH2098
{
// Ignore IO exceptions when deleting temporary files
}
#pragma warning restore PH2098
}
}
catch(InvalidOperationException) {}
catch(Exception)
{
Dispatcher.UIThread.Post(() => Importers.Add(new RomImporter
{
Filename = Path.GetFileName(archive),
Indeterminate = false,
Progress = 1,
Maximum = 1,
Minimum = 0,
StatusMessage = Localization.ErrorProcessingArchive
}));
#pragma warning disable ERP022
}
#pragma warning restore ERP022
finally
{
Interlocked.Increment(ref _listPosition);

View File

@@ -1,5 +0,0 @@
{
"sdk": {
"version": "9.0.301"
}
}