mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Make detection of archive be multithread.
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RomRepoMgr.Core.Aaru;
|
using RomRepoMgr.Core.Aaru;
|
||||||
@@ -83,57 +85,61 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
Maximum = Files.Count
|
Maximum = Files.Count
|
||||||
});
|
});
|
||||||
|
|
||||||
List<string> files = [];
|
ConcurrentBag<string> files = [];
|
||||||
Archives = [];
|
ConcurrentBag<string> archives = [];
|
||||||
|
|
||||||
foreach(string file in Files)
|
Parallel.ForEach(Files,
|
||||||
{
|
file =>
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
SetProgress?.Invoke(this,
|
{
|
||||||
new ProgressEventArgs
|
SetProgress?.Invoke(this,
|
||||||
{
|
new ProgressEventArgs
|
||||||
Value = _position
|
{
|
||||||
});
|
Value = _position
|
||||||
|
});
|
||||||
|
|
||||||
SetMessage?.Invoke(this,
|
SetMessage?.Invoke(this,
|
||||||
new MessageEventArgs
|
new MessageEventArgs
|
||||||
{
|
{
|
||||||
Message = "Checking archives. Found " +
|
Message = "Checking archives. Found " +
|
||||||
Archives.Count +
|
archives.Count +
|
||||||
" archives and " +
|
" archives and " +
|
||||||
files.Count +
|
files.Count +
|
||||||
" files."
|
" files."
|
||||||
});
|
});
|
||||||
|
|
||||||
SetMessage2?.Invoke(this,
|
SetMessage2?.Invoke(this,
|
||||||
new MessageEventArgs
|
new MessageEventArgs
|
||||||
{
|
{
|
||||||
Message = string.Format("Checking if file {0} is an archive...",
|
Message =
|
||||||
Path.GetFileName(file))
|
$"Checking if file {Path.GetFileName(file)} is an archive..."
|
||||||
});
|
});
|
||||||
|
|
||||||
SetIndeterminateProgress2?.Invoke(this, System.EventArgs.Empty);
|
SetIndeterminateProgress2?.Invoke(this, System.EventArgs.Empty);
|
||||||
|
|
||||||
string archiveFormat = GetArchiveFormat(file, out _);
|
string archiveFormat = GetArchiveFormat(file, out _);
|
||||||
|
|
||||||
// If a floppy contains only the archive, unar will recognize it, on its skipping of SFXs.
|
// If a floppy contains only the archive, unar will recognize it, on its skipping of SFXs.
|
||||||
if(archiveFormat != null && FAT.Identify(file)) archiveFormat = null;
|
if(archiveFormat != null && FAT.Identify(file)) archiveFormat = null;
|
||||||
|
|
||||||
if(archiveFormat != null)
|
if(archiveFormat != null)
|
||||||
Archives.Add(file);
|
archives.Add(file);
|
||||||
else
|
else
|
||||||
files.Add(file);
|
files.Add(file);
|
||||||
|
|
||||||
_position++;
|
Interlocked.Increment(ref _position);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Exception while checking file {0}: {1}", Path.GetFileName(file), ex.Message);
|
Console.WriteLine("Exception while checking file {0}: {1}",
|
||||||
}
|
Path.GetFileName(file),
|
||||||
}
|
ex.Message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Files = files;
|
Files = files.ToList();
|
||||||
|
Archives = archives.ToList();
|
||||||
|
|
||||||
SetMessage?.Invoke(this,
|
SetMessage?.Invoke(this,
|
||||||
new MessageEventArgs
|
new MessageEventArgs
|
||||||
|
|||||||
Reference in New Issue
Block a user