-
Notifications
You must be signed in to change notification settings - Fork 0
/
folders.js
74 lines (60 loc) · 2.09 KB
/
folders.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var g_FoldersMap;//Key = Unique Relative Subfolder, Value =Full Path to file
//*****************GET FILE DIRECTORY***************
function getFileDirectory(filePath)
{
if (filePath.indexOf("/") == -1) { // windows
return filePath.substring(0, filePath.lastIndexOf('\\'));
}
else
{ // unix
return filePath.substring(0, filePath.lastIndexOf('/'));
}
}
//Initially I tried to use Folders, but ended up using genre instead with subfolder in that.
//*******************INIT FOLDERS****************************
function InitFolders(games_arr)
{
//console.log("INITFOLDERS");
var FoldersMap = new Map();
for (let i = 0; i < games_arr.length; i++)
{
var game=games_arr[i];
var genreStr = game.genre;
if (genreStr.length < 1)
continue;
genreStr=genreStr.trim();
if (genreStr.length < 1)
continue;
if (FoldersMap.has(genreStr)==false)
{
FoldersMap.set(genreStr, game.files.get(0).path);
}
//If we have something like sports/hockey I want sports to also be a filter on it's own.
var parentDir = "";
parentDir = getFileDirectory(genreStr);
if (parentDir.length>0)
{
if (FoldersMap.has(parentDir)==false)
{
FoldersMap.set(parentDir, game.files.get(0).path);
}
}
}
//Sort It. case INsensitive. so r comes before Z
g_FoldersMap = new Map([...FoldersMap.entries()].sort(function (a, b)
{
var aStr = String(a).toLowerCase();
var bStr = String(b).toLowerCase()
if (aStr < bStr) return -1;
if (aStr > bStr) return 1;
return 0;
}))
//Log g_FoldersMap TODO: comment out when done
//console.log("g_FoldersMap >>>>>>>>>>>>>");
//for (const [key, value] of g_FoldersMap.entries())
//{
//console.log(key +' -> ' + value);
//}
console.log('genres detected: ' + g_FoldersMap.size);
return;
}