| 9168 | return { |
| 9169 | calculated: successCount, |
| 9170 | failed: failedCount, |
| 9171 | total: modelsWithMissingHashes.length |
| 9172 | }; |
| 9173 | } catch (error) { |
| 9174 | isGeneratingHashes = false; |
| 9175 | console.error('Error calculating missing hashes:', error); |
| 9176 | throw error; |
| 9177 | } |
| 9178 | } |
| 9179 | |
| 9180 | // Add IPC handler to calculate missing hashes |
| 9181 | ipcMain.handle('calculate-missing-hashes', async (event) => { |
| 9182 | return await calculateMissingHashesInternal(event); |
| 9183 | }); |
| 9184 | |
| 9185 | // Add IPC handler for generateMissingHashes (calls the same internal function) |
| 9186 | ipcMain.handle('generateMissingHashes', async (event) => { |
| 9187 | // Check if hash generation is already in progress |
| 9188 | if (isGeneratingHashes) { |
| 9189 | console.log('Hash generation already in progress, returning current status'); |
| 9190 | // Return a status indicating it's already running |
| 9191 | // The caller should attach to existing progress events |
| 9192 | const modelsWithMissingHashes = db.prepare(` |
| 9193 | SELECT COUNT(*) as count |
| 9194 | FROM models |
| 9195 | WHERE hash IS NULL OR hash = '' OR LENGTH(hash) = 64 |
| 9196 | `).get(); |
| 9197 | return { |
| 9198 | alreadyRunning: true, |
| 9199 | total: modelsWithMissingHashes ? modelsWithMissingHashes.count : 0 |
| 9200 | }; |
| 9201 | } |
| 9202 | return await calculateMissingHashesInternal(event); |
| 9203 | }); |
| 9204 | |
| 9205 | // Add IPC handler to get count of models without hash |
| 9206 | ipcMain.handle('getModelsWithoutHash', async () => { |
| 9207 | try { |
| 9208 | const result = db.prepare(` |
| 9209 | SELECT COUNT(*) as count |
| 9210 | FROM models |
| 9211 | WHERE hash IS NULL OR hash = '' OR LENGTH(hash) = 64 |
| 9212 | `).get(); |
| 9213 | return result ? result.count : 0; |
| 9214 | } catch (error) { |
| 9215 | console.error('Error getting models without hash:', error); |
| 9216 | return 0; |
| 9217 | } |
| 9218 | }); |
| 9219 | |
| 9220 | // Add IPC handler to check if hash generation is in progress |
| 9221 | ipcMain.handle('is-generating-hashes', async () => { |
| 9222 | return isGeneratingHashes; |
| 9223 | }); |
| 9224 | |
| 9225 | // Add IPC handler to calculate and save hash for a single file |
| 9226 | ipcMain.handle('calculate-file-hash', async (event, filePath) => { |
| 9227 | if (isUrlModel(filePath)) return ''; |