Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
Desktop Client
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SpinShare
Desktop Client
Commits
9e188be4
Commit
9e188be4
authored
Apr 11, 2021
by
Laura Heimann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sqlite database implementation for chartLibrary
parent
477e9099
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
13 deletions
+63
-13
src/modules/module.library.js
src/modules/module.library.js
+63
-13
No files found.
src/modules/module.library.js
View file @
9e188be4
...
...
@@ -5,19 +5,40 @@ const fs = require('fs');
const
{
glob
}
=
require
(
'
glob
'
);
const
path
=
require
(
'
path
'
);
const
UserSettings
=
require
(
'
@/modules/module.usersettings.js
'
);
const
sqlite3
=
require
(
'
sqlite3
'
).
verbose
();
class
ChartLibrary
{
constructor
()
{
const
userDataPath
=
app
.
getPath
(
'
userData
'
);
this
.
path
=
path
.
join
(
userDataPath
,
'
ChartLibrary.json
'
);
this
.
path
=
path
.
join
(
userDataPath
,
'
ChartLibrary.sqlite
'
);
this
.
db
=
null
;
}
async
getLibrary
()
{
let
userSettings
=
new
UserSettings
();
let
data
=
this
.
parseDataFile
(
this
.
path
,
false
);
console
.
log
(
"
[ChartLibrary] Get Library
"
);
this
.
connectToDatabase
();
this
.
db
.
serialize
(()
=>
{
this
.
createDatabaseIfNotExists
();
// TODO: Check if Database is up to date and update if not
this
.
db
.
get
(
'
SELECT * FROM meta
'
,
(
err
,
row
)
=>
{
if
(
err
)
{
console
.
error
(
"
[ChartLibrary]
"
+
err
.
message
);
}
console
.
log
(
row
);
});
// TODO: Get Library
});
this
.
closeDatabase
();
/*
let data = this.parseDataFile(this.path, false);
if(data == false) {
return this.updateLibrary();
} else {
...
...
@@ -26,18 +47,29 @@ class ChartLibrary {
} else {
return data;
}
}
}
*/
}
async
updateLibrary
()
{
console
.
log
(
"
[ChartLibrary] Library Refresh
"
);
this
.
connectToDatabase
();
this
.
db
.
serialize
(()
=>
{
this
.
createDatabaseIfNotExists
();
// TODO: Update Library and Save to DB
});
this
.
closeDatabase
();
/*
let userSettings = new UserSettings();
let data = {
folderMD5: "",
charts: []
};
console
.
log
(
"
[ChartLibrary] Library Refresh
"
);
data.folderMD5 = md5(userSettings.get('gameDirectory'));
// Find all SRTB files
...
...
@@ -58,6 +90,7 @@ class ChartLibrary {
console.log("[ChartLibrary] Wrote Library to: " + this.path);
return data;
*/
}
parseSRTBFile
(
srtbFilePath
)
{
...
...
@@ -180,12 +213,29 @@ class ChartLibrary {
return
data
;
}
parseDataFile
(
filePath
,
defaults
)
{
try
{
return
JSON
.
parse
(
fs
.
readFileSync
(
filePath
));
}
catch
(
error
)
{
return
defaults
;
}
connectToDatabase
()
{
this
.
db
=
new
sqlite3
.
Database
(
this
.
path
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
"
[ChartLibrary]
"
+
err
.
message
);
}
console
.
log
(
'
[ChartLibrary] Connected to Database
'
);
});
}
closeDatabase
()
{
this
.
db
.
close
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
"
[ChartLibrary]
"
+
err
.
message
);
}
console
.
log
(
'
[ChartLibrary] Database Closed
'
);
});
}
createDatabaseIfNotExists
()
{
// TODO: Finalize Database Structure
this
.
db
.
prepare
(
`
CREATE TABLE IF NOT EXISTS meta (folderMD5 TEXT, clientVersion TEXT);
`
).
run
().
finalize
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment