Skip to content

Commit 73d8c5e

Browse files
committed
add games with no match
1 parent 52c67f9 commit 73d8c5e

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

src/main/main.ts

+38-36
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ if (!fs.existsSync(dbPathLibrary)) {
138138
}
139139
console.log('Conexión exitosa a la base de datos.');
140140

141-
// Define aquí tus comandos SQL para crear tablas
142141
const createTableSql = `CREATE TABLE "roms" (
143142
"id" INTEGER,
144143
"file_name" TEXT,
@@ -152,7 +151,7 @@ if (!fs.existsSync(dbPathLibrary)) {
152151
"favourite" INTEGER DEFAULT 0,
153152
PRIMARY KEY("id" AUTOINCREMENT),
154153
UNIQUE("file_name")
155-
)`; // Asegúrate de reemplazar esto con tu SQL para crear tablas
154+
)`;
156155
db.run(createTableSql, (err) => {
157156
if (err) {
158157
console.error(err.message);
@@ -590,46 +589,49 @@ const insertROM = (
590589
// db.all(query, [`%${romNameForSearch}%`, platform], (err, rows) => {
591590
db.all(query, [`%${romNameForSearch}%`, platform], (err, rows) => {
592591
const results = rows;
593-
592+
const imageData = {
593+
gameFile,
594+
romNameTrimmed,
595+
folderName,
596+
platform,
597+
gameFilePath,
598+
};
594599
if (results.length > 0) {
595-
const insertQuery = `
596-
INSERT OR REPLACE INTO roms (file_name, name, system, platform, path, databaseID)
597-
VALUES (?, ?, ?, ?, ?, ?)
598-
`;
599-
const imageData = {
600-
gameFile,
601-
romNameTrimmed,
602-
folderName,
603-
platform,
604-
gameFilePath,
605-
};
606600
results.forEach((result) => {
607601
imageData.databaseID = result.DatabaseID;
608602
});
609-
// console.log({ imageData });
610-
dbLibrary.run(
611-
insertQuery,
612-
[
613-
imageData.gameFile,
614-
imageData.romNameTrimmed,
615-
imageData.folderName,
616-
imageData.platform,
617-
imageData.gameFilePath,
618-
imageData.databaseID,
619-
],
620-
function (err) {
603+
} else {
604+
imageData.databaseID = 0;
605+
}
606+
607+
const insertQuery = `
608+
INSERT OR REPLACE INTO roms (file_name, name, system, platform, path, databaseID)
609+
VALUES (?, ?, ?, ?, ?, ?)
610+
`;
611+
612+
// console.log({ imageData });
613+
dbLibrary.run(
614+
insertQuery,
615+
[
616+
imageData.gameFile,
617+
imageData.romNameTrimmed,
618+
imageData.folderName,
619+
imageData.platform,
620+
imageData.gameFilePath,
621+
imageData.databaseID,
622+
],
623+
function (err) {
624+
if (err) {
625+
return console.error('Error al insertar datos:', err.message);
626+
}
627+
fs.writeFile(fileCachePath, '', (err) => {
621628
if (err) {
622-
return console.error('Error al insertar datos:', err.message);
629+
console.error('Error writing the file:', err);
623630
}
624-
fs.writeFile(fileCachePath, '', (err) => {
625-
if (err) {
626-
console.error('Error writing the file:', err);
627-
}
628-
});
629-
},
630-
);
631-
dbLibrary.close();
632-
}
631+
});
632+
},
633+
);
634+
dbLibrary.close();
633635
});
634636
};
635637

0 commit comments

Comments
 (0)