Added a library scan button (#417)
This commit is contained in:
@@ -175,6 +175,24 @@ namespace gaseous_server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LibraryItem ScanLibrary(int LibraryId)
|
||||||
|
{
|
||||||
|
// add the library to scan to the queue
|
||||||
|
LibraryItem library = GetLibrary(LibraryId);
|
||||||
|
ImportGame.LibrariesToScan.Add(library);
|
||||||
|
|
||||||
|
// start the library scan if it's not already running
|
||||||
|
foreach (ProcessQueue.QueueItem item in ProcessQueue.QueueItems)
|
||||||
|
{
|
||||||
|
if (item.ItemType == ProcessQueue.QueueItemType.LibraryScan && item.ItemState != ProcessQueue.QueueItemState.Running)
|
||||||
|
{
|
||||||
|
item.ForceExecute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return library;
|
||||||
|
}
|
||||||
|
|
||||||
public class LibraryItem
|
public class LibraryItem
|
||||||
{
|
{
|
||||||
public LibraryItem(int Id, string Name, string Path, long DefaultPlatformId, bool IsDefaultLibrary)
|
public LibraryItem(int Id, string Name, string Path, long DefaultPlatformId, bool IsDefaultLibrary)
|
||||||
|
@@ -523,61 +523,82 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LibraryScan(GameLibrary.LibraryItem? singleLibrary = null)
|
public static List<GameLibrary.LibraryItem> LibrariesToScan = new List<GameLibrary.LibraryItem>();
|
||||||
|
public void LibraryScan()
|
||||||
{
|
{
|
||||||
int maxWorkers = Config.MetadataConfiguration.MaxLibraryScanWorkers;
|
int maxWorkers = Config.MetadataConfiguration.MaxLibraryScanWorkers;
|
||||||
|
|
||||||
List<GameLibrary.LibraryItem> libraries = new List<GameLibrary.LibraryItem>();
|
if (LibrariesToScan.Count == 0)
|
||||||
if (singleLibrary == null)
|
|
||||||
{
|
{
|
||||||
libraries.AddRange(GameLibrary.GetLibraries);
|
LibrariesToScan.AddRange(GameLibrary.GetLibraries);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
libraries.Add(singleLibrary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup background tasks for each library
|
// setup background tasks for each library
|
||||||
foreach (GameLibrary.LibraryItem library in libraries)
|
do
|
||||||
{
|
{
|
||||||
Logging.Log(Logging.LogType.Information, "Library Scan", "Starting worker process for library " + library.Name);
|
Logging.Log(Logging.LogType.Information, "Library Scan", "Library scan queue size: " + LibrariesToScan.Count);
|
||||||
ProcessQueue.QueueItem queue = new ProcessQueue.QueueItem(
|
|
||||||
ProcessQueue.QueueItemType.LibraryScanWorker,
|
|
||||||
1,
|
|
||||||
new List<ProcessQueue.QueueItemType>
|
|
||||||
{
|
|
||||||
ProcessQueue.QueueItemType.OrganiseLibrary,
|
|
||||||
ProcessQueue.QueueItemType.Rematcher
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
true);
|
|
||||||
queue.Options = library;
|
|
||||||
queue.ForceExecute();
|
|
||||||
|
|
||||||
ProcessQueue.QueueItems.Add(queue);
|
GameLibrary.LibraryItem library = LibrariesToScan[0];
|
||||||
|
LibrariesToScan.RemoveAt(0);
|
||||||
|
|
||||||
// check number of running tasks is less than maxWorkers
|
// check if library is already being scanned
|
||||||
bool allowContinue;
|
bool libraryAlreadyScanning = false;
|
||||||
do
|
List<ProcessQueue.QueueItem> ProcessQueueItems = new List<ProcessQueue.QueueItem>();
|
||||||
|
ProcessQueueItems.AddRange(ProcessQueue.QueueItems);
|
||||||
|
foreach (ProcessQueue.QueueItem item in ProcessQueueItems)
|
||||||
{
|
{
|
||||||
allowContinue = true;
|
if (item.ItemType == ProcessQueue.QueueItemType.LibraryScanWorker)
|
||||||
int currentWorkerCount = 0;
|
|
||||||
List<ProcessQueue.QueueItem> queueItems = new List<ProcessQueue.QueueItem>();
|
|
||||||
queueItems.AddRange(ProcessQueue.QueueItems);
|
|
||||||
foreach (ProcessQueue.QueueItem item in queueItems)
|
|
||||||
{
|
{
|
||||||
if (item.ItemType == ProcessQueue.QueueItemType.LibraryScanWorker)
|
if (((GameLibrary.LibraryItem)item.Options).Id == library.Id)
|
||||||
{
|
{
|
||||||
currentWorkerCount += 1;
|
libraryAlreadyScanning = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentWorkerCount >= maxWorkers)
|
}
|
||||||
|
|
||||||
|
if (libraryAlreadyScanning == false)
|
||||||
|
{
|
||||||
|
Logging.Log(Logging.LogType.Information, "Library Scan", "Starting worker process for library " + library.Name);
|
||||||
|
ProcessQueue.QueueItem queue = new ProcessQueue.QueueItem(
|
||||||
|
ProcessQueue.QueueItemType.LibraryScanWorker,
|
||||||
|
1,
|
||||||
|
new List<ProcessQueue.QueueItemType>
|
||||||
|
{
|
||||||
|
ProcessQueue.QueueItemType.OrganiseLibrary,
|
||||||
|
ProcessQueue.QueueItemType.Rematcher
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
true)
|
||||||
{
|
{
|
||||||
allowContinue = false;
|
Options = library
|
||||||
Thread.Sleep(60000);
|
};
|
||||||
}
|
queue.ForceExecute();
|
||||||
} while (allowContinue == false);
|
|
||||||
}
|
ProcessQueue.QueueItems.Add(queue);
|
||||||
|
|
||||||
|
// check number of running tasks is less than maxWorkers
|
||||||
|
bool allowContinue;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
allowContinue = true;
|
||||||
|
int currentWorkerCount = 0;
|
||||||
|
List<ProcessQueue.QueueItem> LibraryScan_QueueItems = new List<ProcessQueue.QueueItem>();
|
||||||
|
LibraryScan_QueueItems.AddRange(ProcessQueue.QueueItems);
|
||||||
|
foreach (ProcessQueue.QueueItem item in LibraryScan_QueueItems)
|
||||||
|
{
|
||||||
|
if (item.ItemType == ProcessQueue.QueueItemType.LibraryScanWorker)
|
||||||
|
{
|
||||||
|
currentWorkerCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentWorkerCount >= maxWorkers)
|
||||||
|
{
|
||||||
|
allowContinue = false;
|
||||||
|
Thread.Sleep(60000);
|
||||||
|
}
|
||||||
|
} while (allowContinue == false);
|
||||||
|
}
|
||||||
|
} while (LibrariesToScan.Count > 0);
|
||||||
|
|
||||||
bool WorkersStillWorking;
|
bool WorkersStillWorking;
|
||||||
do
|
do
|
||||||
@@ -597,6 +618,12 @@ namespace gaseous_server.Classes
|
|||||||
} while (WorkersStillWorking == true);
|
} while (WorkersStillWorking == true);
|
||||||
|
|
||||||
Logging.Log(Logging.LogType.Information, "Library Scan", "Library scan complete. All workers stopped");
|
Logging.Log(Logging.LogType.Information, "Library Scan", "Library scan complete. All workers stopped");
|
||||||
|
|
||||||
|
if (LibrariesToScan.Count > 0)
|
||||||
|
{
|
||||||
|
Logging.Log(Logging.LogType.Information, "Library Scan", "There are still libraries to scan. Restarting scan process");
|
||||||
|
LibraryScan();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LibrarySpecificScan(GameLibrary.LibraryItem library)
|
public void LibrarySpecificScan(GameLibrary.LibraryItem library)
|
||||||
|
@@ -86,5 +86,24 @@ namespace gaseous_server.Controllers
|
|||||||
return NotFound(exLNF.ToString());
|
return NotFound(exLNF.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MapToApiVersion("1.0")]
|
||||||
|
[MapToApiVersion("1.1")]
|
||||||
|
[HttpPost("{LibraryId}/Scan")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public ActionResult ScanLibrary(int LibraryId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GameLibrary.ScanLibrary(LibraryId);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (GameLibrary.LibraryNotFound exLNF)
|
||||||
|
{
|
||||||
|
return NotFound(exLNF.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -335,7 +335,14 @@
|
|||||||
"Extensions": {
|
"Extensions": {
|
||||||
"SupportedFileExtensions": [
|
"SupportedFileExtensions": [
|
||||||
".CPC",
|
".CPC",
|
||||||
".DSK"
|
".DSK",
|
||||||
|
".SNA",
|
||||||
|
".TAP",
|
||||||
|
".CDT",
|
||||||
|
".VOC",
|
||||||
|
".M3U",
|
||||||
|
".CPR",
|
||||||
|
".ZIP"
|
||||||
],
|
],
|
||||||
"UniqueFileExtensions": [
|
"UniqueFileExtensions": [
|
||||||
".CPC"
|
".CPC"
|
||||||
@@ -343,9 +350,25 @@
|
|||||||
},
|
},
|
||||||
"RetroPieDirectoryName": "amstradcpc",
|
"RetroPieDirectoryName": "amstradcpc",
|
||||||
"WebEmulator": {
|
"WebEmulator": {
|
||||||
"Type": "",
|
"Type": "EmulatorJS",
|
||||||
"Core": "",
|
"Core": "crocods",
|
||||||
"AvailableWebEmulators": []
|
"AvailableWebEmulators": [
|
||||||
|
{
|
||||||
|
"EmulatorType": "EmulatorJS",
|
||||||
|
"AvailableWebEmulatorCores": [
|
||||||
|
{
|
||||||
|
"Core": "crocods",
|
||||||
|
"AlternateCoreName": "",
|
||||||
|
"Default": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Core": "cap32",
|
||||||
|
"AlternateCoreName": "",
|
||||||
|
"Default": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"Bios": []
|
"Bios": []
|
||||||
},
|
},
|
||||||
@@ -3442,14 +3465,35 @@
|
|||||||
"SFC"
|
"SFC"
|
||||||
],
|
],
|
||||||
"Extensions": {
|
"Extensions": {
|
||||||
"SupportedFileExtensions": [],
|
"SupportedFileExtensions": [
|
||||||
|
".7Z",
|
||||||
|
".BIN",
|
||||||
|
".BS",
|
||||||
|
".FIG",
|
||||||
|
".MGD",
|
||||||
|
".SFC",
|
||||||
|
".SMC",
|
||||||
|
".SWC",
|
||||||
|
".ZIP"
|
||||||
|
],
|
||||||
"UniqueFileExtensions": []
|
"UniqueFileExtensions": []
|
||||||
},
|
},
|
||||||
"RetroPieDirectoryName": "",
|
"RetroPieDirectoryName": "snes",
|
||||||
"WebEmulator": {
|
"WebEmulator": {
|
||||||
"Type": "",
|
"Type": "EmulatorJS",
|
||||||
"Core": "",
|
"Core": "snes",
|
||||||
"AvailableWebEmulators": null
|
"AvailableWebEmulators": [
|
||||||
|
{
|
||||||
|
"EmulatorType": "EmulatorJS",
|
||||||
|
"AvailableWebEmulatorCores": [
|
||||||
|
{
|
||||||
|
"Core": "snes",
|
||||||
|
"AlternateCoreName": "snes9x",
|
||||||
|
"Default": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"Bios": []
|
"Bios": []
|
||||||
},
|
},
|
||||||
|
@@ -12,7 +12,7 @@ function drawLibrary() {
|
|||||||
function (result) {
|
function (result) {
|
||||||
let newTable = document.getElementById('settings_libraries');
|
let newTable = document.getElementById('settings_libraries');
|
||||||
newTable.innerHTML = '';
|
newTable.innerHTML = '';
|
||||||
newTable.appendChild(createTableRow(true, ['Name', 'Path', 'Default Platform', 'Default Library', '']));
|
newTable.appendChild(createTableRow(true, ['Name', 'Path', 'Default Platform', 'Default Library', '', '']));
|
||||||
|
|
||||||
for (let i = 0; i < result.length; i++) {
|
for (let i = 0; i < result.length; i++) {
|
||||||
let platformName = '';
|
let platformName = '';
|
||||||
@@ -36,6 +36,35 @@ function drawLibrary() {
|
|||||||
let controls = document.createElement('div');
|
let controls = document.createElement('div');
|
||||||
controls.style.textAlign = 'right';
|
controls.style.textAlign = 'right';
|
||||||
|
|
||||||
|
let scanButton = document.createElement('img');
|
||||||
|
scanButton.id = 'startProcess';
|
||||||
|
scanButton.className = 'taskstart';
|
||||||
|
scanButton.src = '/images/start-task.svg';
|
||||||
|
scanButton.title = 'Start Scan';
|
||||||
|
scanButton.addEventListener('click', function () {
|
||||||
|
let scanLibrary = new MessageBox('Scan Library', 'Are you sure you want to scan this library?');
|
||||||
|
scanLibrary.addButton(new ModalButton('OK', 2, scanLibrary, function (callingObject) {
|
||||||
|
ajaxCall(
|
||||||
|
'/api/v1.1/Library/' + result[i].id + '/Scan',
|
||||||
|
'POST',
|
||||||
|
function () {
|
||||||
|
callingObject.msgDialog.close();
|
||||||
|
drawLibrary();
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
callingObject.msgDialog.close();
|
||||||
|
drawLibrary();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
scanLibrary.addButton(new ModalButton('Cancel', 0, scanLibrary, function (callingObject) {
|
||||||
|
callingObject.msgDialog.close();
|
||||||
|
}));
|
||||||
|
|
||||||
|
scanLibrary.open();
|
||||||
|
});
|
||||||
|
|
||||||
let deleteButton = '';
|
let deleteButton = '';
|
||||||
if (result[i].isDefaultLibrary == false) {
|
if (result[i].isDefaultLibrary == false) {
|
||||||
deleteButton = document.createElement('a');
|
deleteButton = document.createElement('a');
|
||||||
@@ -80,6 +109,7 @@ function drawLibrary() {
|
|||||||
result[i].path,
|
result[i].path,
|
||||||
platformName,
|
platformName,
|
||||||
defaultLibrary,
|
defaultLibrary,
|
||||||
|
scanButton,
|
||||||
controls
|
controls
|
||||||
],
|
],
|
||||||
'romrow',
|
'romrow',
|
||||||
|
Reference in New Issue
Block a user