commit 58c43a58d472124f05585109e2fa83c94f42261f Author: Turleynerd <4308353+turleynerd@users.noreply.github.com> Date: Sat Sep 2 20:19:56 2023 -0400 init diff --git a/app.ts b/app.ts new file mode 100644 index 0000000..c4c95ad --- /dev/null +++ b/app.ts @@ -0,0 +1,92 @@ +import { app, BrowserWindow } from 'electron'; +import { download } from 'electron-dl'; + +// Files to download +const files: string[] = [ + 'info.txt', + 'patch-4.mpq', + 'patch-5.mpq', + 'patch-7.mpq', + 'patch-9.mpq', + 'patch-B.mpq', + 'patch-C.mpq', + 'patch-D.mpq', + 'patch-F.mpq', + 'patch-G.mpq', + 'patch-J.mpq', + 'patch-L.mpq', + 'patch-S.mpq', + 'patch-T.mpq', + 'patch-U.mpq', +]; + +const patchSource = 'https://storage.googleapis.com/araxia-client-patches/'; +const appName = 'Araxia Client Patch Downloader'; + +let mainWindow: BrowserWindow | null; + +function createWindow() { + // Create the browser window + mainWindow = new BrowserWindow({ + width: 800, + height: 600, + webPreferences: { + nodeIntegration: true, + }, + }); + + // Load the index.html file + mainWindow.loadFile('index.html'); + + // Open the DevTools. + // mainWindow.webContents.openDevTools(); + + // Emitted when the window is closed + mainWindow.on('closed', function () { + mainWindow = null; + }); + + // Handle the close button click + mainWindow.on('close', function (e) { + // Prevent the window from closing immediately + e.preventDefault(); + app.quit(); + }); +} + +// Create the main window when the app is ready +app.on('ready', createWindow); + +// Quit the app when all windows are closed (except on macOS) +app.on('window-all-closed', function () { + if (process.platform !== 'darwin') { + app.quit(); + } +}); + +// Create a new window when the app is activated (on macOS) +app.on('activate', function () { + if (mainWindow === null) { + createWindow(); + } +}); + +// Handle file downloads +app.on('ready', function () { + // Specify the directory where files will be downloaded + const directory = app.getPath('userData'); + + // Download each file in parallel + files.forEach((file, index) => { + download(mainWindow, patchSource + file, { directory, filename: file }) + .then(() => { + // File downloaded successfully + console.log(`File ${file} downloaded.`); + mainWindow?.webContents.send('update-progress', { index, progress: 100 }); + }) + .catch((error) => { + // Error occurred during download + console.error(`Error downloading file ${file}: ${error}`); + }); + }); +}); diff --git a/index.html b/index.html new file mode 100644 index 0000000..85cd24c --- /dev/null +++ b/index.html @@ -0,0 +1,18 @@ + + + + + + Araxia Client Patch Downloader + + + +
+

Araxia Client Patch Downloader

+
+ +
+
+ + + diff --git a/renderer.js b/renderer.js new file mode 100644 index 0000000..a7c3a2e --- /dev/null +++ b/renderer.js @@ -0,0 +1,38 @@ +const { ipcRenderer } = require('electron'); + +document.addEventListener('DOMContentLoaded', () => { + // Listen for progress update messages from the main process + ipcRenderer.on('update-progress', (event, data) => { + updateProgressBar(data.index, data.progress); + }); +}); + +// Function to update the progress bar for a specific file +function updateProgressBar(index, progress) { + const progressBar = document.getElementById(`progress-bar-${index}`); + if (progressBar) { + const progressBarInner = progressBar.querySelector('.progress'); + progressBarInner.style.width = `${progress}%`; + + // Update the progress label + const progressLabel = progressBar.querySelector('.progress-label'); + progressLabel.textContent = `File ${index} (${progress}%)`; + + // Update the download speed if available + const progressSpeed = progressBar.querySelector('.progress-speed'); + if (progressSpeed) { + progressSpeed.textContent = `Speed: ${getFormattedSpeed()}` + } + } +} + +// Function to format the download speed +function getFormattedSpeed(speed) { + if (speed < 1024) { + return `${speed.toFixed(2)} B/s`; + } else if (speed < 1024 * 1024) { + return `${(speed / 1024).toFixed(2)} KB/s`; + } else { + return `${(speed / 1024 / 1024).toFixed(2)} MB/s`; + } +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..b58e70a --- /dev/null +++ b/style.css @@ -0,0 +1,67 @@ +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + background-color: #f0f0f0; + } + + .container { + max-width: 800px; + margin: 0 auto; + padding: 20px; + text-align: center; + background-color: #fff; + box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); + border-radius: 5px; + position: relative; + top: 50%; + transform: translateY(-50%); + } + + h1 { + font-size: 24px; + margin-bottom: 20px; + } + + .progress-bars { + text-align: left; + } + + .progress-bar { + margin-bottom: 10px; + display: flex; + justify-content: space-between; + align-items: center; + } + + .progress-label { + flex: 1; + margin-right: 10px; + font-weight: bold; + } + + .progress-bar-inner { + flex: 4; + } + + .progressBar { + width: 100%; + height: 20px; + border-radius: 5px; + background-color: #f0f0f0; + overflow: hidden; + } + + .progressBar .progress { + height: 100%; + background-color: #007bff; + transition: width 0.3s ease-in-out; + } + + .progress-speed { + flex: 1; + font-size: 12px; + text-align: right; + color: #888; + } + \ No newline at end of file