mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Use a different, more agressive, method to parallelize archive import, that better uses available threads/cores.
This commit is contained in:
@@ -356,10 +356,14 @@ public class ImportRomFolderViewModel : ViewModelBase
|
|||||||
_listPosition = 0;
|
_listPosition = 0;
|
||||||
_stopwatch.Restart();
|
_stopwatch.Restart();
|
||||||
|
|
||||||
foreach(string archive in _rootImporter.Archives)
|
Parallel.ForEach(_rootImporter.Archives,
|
||||||
{
|
archive =>
|
||||||
StatusMessage = "Processing archive: " + Path.GetFileName(archive);
|
{
|
||||||
ProgressValue = _listPosition++;
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
|
StatusMessage = "Processing archive: " + Path.GetFileName(archive);
|
||||||
|
ProgressValue = _listPosition;
|
||||||
|
});
|
||||||
|
|
||||||
// Create FileImporter
|
// Create FileImporter
|
||||||
var archiveImporter = new FileImporter(KnownOnlyChecked, RemoveFilesChecked);
|
var archiveImporter = new FileImporter(KnownOnlyChecked, RemoveFilesChecked);
|
||||||
@@ -372,11 +376,10 @@ public class ImportRomFolderViewModel : ViewModelBase
|
|||||||
// Extract archive
|
// Extract archive
|
||||||
bool ret = archiveImporter.ExtractArchive(archive);
|
bool ret = archiveImporter.ExtractArchive(archive);
|
||||||
|
|
||||||
if(!ret) continue;
|
if(!ret) return;
|
||||||
|
|
||||||
// Process files in archive
|
// Process files in archive
|
||||||
Parallel.ForEach(archiveImporter.Files,
|
foreach(string file in archiveImporter.Files)
|
||||||
file =>
|
|
||||||
{
|
{
|
||||||
var model = new RomImporter
|
var model = new RomImporter
|
||||||
{
|
{
|
||||||
@@ -396,17 +399,14 @@ public class ImportRomFolderViewModel : ViewModelBase
|
|||||||
|
|
||||||
worker.ImportFile(file);
|
worker.ImportFile(file);
|
||||||
|
|
||||||
worker.SaveChanges();
|
|
||||||
|
|
||||||
worker.Files.Clear();
|
worker.Files.Clear();
|
||||||
});
|
}
|
||||||
|
|
||||||
// Remove temporary files
|
// Remove temporary files
|
||||||
archiveImporter.CleanupExtractedArchive();
|
archiveImporter.CleanupExtractedArchive();
|
||||||
|
|
||||||
// Save database changes
|
Interlocked.Increment(ref _listPosition);
|
||||||
archiveImporter.SaveChanges();
|
});
|
||||||
}
|
|
||||||
|
|
||||||
_stopwatch.Stop();
|
_stopwatch.Stop();
|
||||||
Console.WriteLine("Took " + _stopwatch.Elapsed.TotalSeconds + " seconds to process archives.");
|
Console.WriteLine("Took " + _stopwatch.Elapsed.TotalSeconds + " seconds to process archives.");
|
||||||
|
|||||||
Reference in New Issue
Block a user