diff --git a/package.json b/package.json index 05ccc6ab..10c6f6ea 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,15 @@ ] }, "build": { + "extraResources": [ + { + "from": "./src/extraResources/", + "to": "extraResources", + "filter": [ + "**/*" + ] + } + ], "productName": "ElectronReact", "appId": "org.erb.ElectronReact", "asar": true, diff --git a/src/extraResources/depot-downloader/DepotDownloader.deps.json b/src/extraResources/depot-downloader/DepotDownloader.deps.json new file mode 100644 index 00000000..9bc9da3d --- /dev/null +++ b/src/extraResources/depot-downloader/DepotDownloader.deps.json @@ -0,0 +1,121 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v6.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v6.0": { + "DepotDownloader/2.4.6": { + "dependencies": { + "SteamKit2": "2.4.1", + "protobuf-net": "3.0.101" + }, + "runtime": { + "DepotDownloader.dll": {} + } + }, + "Microsoft.NETCore.Platforms/5.0.0": {}, + "Microsoft.Win32.Registry/5.0.0": { + "dependencies": { + "System.Security.AccessControl": "5.0.0", + "System.Security.Principal.Windows": "5.0.0" + } + }, + "protobuf-net/3.0.101": { + "dependencies": { + "protobuf-net.Core": "3.0.101" + }, + "runtime": { + "lib/net5.0/protobuf-net.dll": { + "assemblyVersion": "3.0.0.0", + "fileVersion": "3.0.101.59408" + } + } + }, + "protobuf-net.Core/3.0.101": { + "runtime": { + "lib/net5.0/protobuf-net.Core.dll": { + "assemblyVersion": "3.0.0.0", + "fileVersion": "3.0.101.59408" + } + } + }, + "SteamKit2/2.4.1": { + "dependencies": { + "Microsoft.Win32.Registry": "5.0.0", + "protobuf-net": "3.0.101" + }, + "runtime": { + "lib/net6.0/SteamKit2.dll": { + "assemblyVersion": "2.4.1.0", + "fileVersion": "2.4.1.10" + } + } + }, + "System.Security.AccessControl/5.0.0": { + "dependencies": { + "Microsoft.NETCore.Platforms": "5.0.0", + "System.Security.Principal.Windows": "5.0.0" + } + }, + "System.Security.Principal.Windows/5.0.0": {} + } + }, + "libraries": { + "DepotDownloader/2.4.6": { + "type": "project", + "serviceable": false, + "sha512": "" + }, + "Microsoft.NETCore.Platforms/5.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-VyPlqzH2wavqquTcYpkIIAQ6WdenuKoFN0BdYBbCWsclXacSOHNQn66Gt4z5NBqEYW0FAPm5rlvki9ZiCij5xQ==", + "path": "microsoft.netcore.platforms/5.0.0", + "hashPath": "microsoft.netcore.platforms.5.0.0.nupkg.sha512" + }, + "Microsoft.Win32.Registry/5.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-dDoKi0PnDz31yAyETfRntsLArTlVAVzUzCIvvEDsDsucrl33Dl8pIJG06ePTJTI3tGpeyHS9Cq7Foc/s4EeKcg==", + "path": "microsoft.win32.registry/5.0.0", + "hashPath": "microsoft.win32.registry.5.0.0.nupkg.sha512" + }, + "protobuf-net/3.0.101": { + "type": "package", + "serviceable": true, + "sha512": "sha512-mLm8VGfGylp9q+rbJDp3uw0BOeNzfGENecVz/EYGlzq3ss7tfajGXHCMoZm/GxJ9vSn9pcK22UXWZnQ5GJQMjA==", + "path": "protobuf-net/3.0.101", + "hashPath": "protobuf-net.3.0.101.nupkg.sha512" + }, + "protobuf-net.Core/3.0.101": { + "type": "package", + "serviceable": true, + "sha512": "sha512-gf9QIF0RlctfjmOjbE6eOyMulkNEsH7tHncjKj/4BTu9tkuTyrH3fv5I+35GnolJqKJ6fh9kYaezvNRL3t75+Q==", + "path": "protobuf-net.core/3.0.101", + "hashPath": "protobuf-net.core.3.0.101.nupkg.sha512" + }, + "SteamKit2/2.4.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-t9yptysn/2YY6KZaI123vOOnumS+ZCFcC6MhFEkTiQ04mdpZ/EWhk5RVY7jU36IQHyTQUXotmn7taKFCXMKp4g==", + "path": "steamkit2/2.4.1", + "hashPath": "steamkit2.2.4.1.nupkg.sha512" + }, + "System.Security.AccessControl/5.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-dagJ1mHZO3Ani8GH0PHpPEe/oYO+rVdbQjvjJkBRNQkX4t0r1iaeGn8+/ybkSLEan3/slM0t59SVdHzuHf2jmw==", + "path": "system.security.accesscontrol/5.0.0", + "hashPath": "system.security.accesscontrol.5.0.0.nupkg.sha512" + }, + "System.Security.Principal.Windows/5.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-t0MGLukB5WAVU9bO3MGzvlGnyJPgUlcwerXn1kzBRjwLKixT96XV0Uza41W49gVd8zEMFu9vQEFlv0IOrytICA==", + "path": "system.security.principal.windows/5.0.0", + "hashPath": "system.security.principal.windows.5.0.0.nupkg.sha512" + } + } +} \ No newline at end of file diff --git a/src/extraResources/depot-downloader/DepotDownloader.dll b/src/extraResources/depot-downloader/DepotDownloader.dll new file mode 100644 index 00000000..6319a47a Binary files /dev/null and b/src/extraResources/depot-downloader/DepotDownloader.dll differ diff --git a/src/extraResources/depot-downloader/DepotDownloader.exe b/src/extraResources/depot-downloader/DepotDownloader.exe new file mode 100644 index 00000000..f0a7af47 Binary files /dev/null and b/src/extraResources/depot-downloader/DepotDownloader.exe differ diff --git a/src/extraResources/depot-downloader/DepotDownloader.pdb b/src/extraResources/depot-downloader/DepotDownloader.pdb new file mode 100644 index 00000000..a9df2d8a Binary files /dev/null and b/src/extraResources/depot-downloader/DepotDownloader.pdb differ diff --git a/src/extraResources/depot-downloader/DepotDownloader.runtimeconfig.json b/src/extraResources/depot-downloader/DepotDownloader.runtimeconfig.json new file mode 100644 index 00000000..3c15255d --- /dev/null +++ b/src/extraResources/depot-downloader/DepotDownloader.runtimeconfig.json @@ -0,0 +1,13 @@ +{ + "runtimeOptions": { + "tfm": "net6.0", + "rollForward": "LatestMajor", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "6.0.0" + }, + "configProperties": { + "System.Reflection.Metadata.MetadataUpdater.IsSupported": false + } + } +} \ No newline at end of file diff --git a/src/extraResources/depot-downloader/SteamKit2.dll b/src/extraResources/depot-downloader/SteamKit2.dll new file mode 100644 index 00000000..48892440 Binary files /dev/null and b/src/extraResources/depot-downloader/SteamKit2.dll differ diff --git a/src/extraResources/depot-downloader/protobuf-net.Core.dll b/src/extraResources/depot-downloader/protobuf-net.Core.dll new file mode 100644 index 00000000..13a805ff Binary files /dev/null and b/src/extraResources/depot-downloader/protobuf-net.Core.dll differ diff --git a/src/extraResources/depot-downloader/protobuf-net.dll b/src/extraResources/depot-downloader/protobuf-net.dll new file mode 100644 index 00000000..4b47f341 Binary files /dev/null and b/src/extraResources/depot-downloader/protobuf-net.dll differ diff --git a/src/main/ipcs/bs-download-ipcs.ts b/src/main/ipcs/bs-download-ipcs.ts new file mode 100644 index 00000000..4b540ff0 --- /dev/null +++ b/src/main/ipcs/bs-download-ipcs.ts @@ -0,0 +1,55 @@ +// const script = path.join(path.dirname(__dirname), 'extraRessources', 'DepotDownloader', 'DepotDownloader.exe');; +// const intance = spawn(script, ['-username lekilleur618', '-manifest 4038188869828689801', '-depot 620981', '-app 620980', '-remember-password'], {cwd: "C:\\test", shell: true}); +// intance.stdout.on('data', (data) =>{ +// console.log(data.toString()); +// if(data.toString().includes('Enter account password for')){ +// intance.stdin.write('MmBopN8qez5gKFZX\n'); +// } +// }); +// intance.stderr.on('data', (data) => console.log(data.toString())); +// intance.on('message', (message) => {console.log(message.toString())}); + +import { ipcMain } from 'electron'; +import path from 'path'; +import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; +import { createFolderIfNotExist } from '../utils'; + + +export interface InitDownloadInfoInterface { + cwd: string , + folder: string, + app: string, + depot: string, + manifest: string, + username: string, + stay: boolean +} + +const DEPOT_DOWNLOADER_EXE = 'DepotDownloader.exe'; +const DEPOT_DOWNLOADER_PATH = path.join(path.dirname(__dirname), '..', 'extraResources', 'depot-downloader', DEPOT_DOWNLOADER_EXE); + +let PROCESS: ChildProcessWithoutNullStreams; + +ipcMain.on('bs-download.start', async (event, args: InitDownloadInfoInterface) => { + console.log(DEPOT_DOWNLOADER_PATH); + console.log(args.cwd); + createFolderIfNotExist(args.cwd); + PROCESS = spawn(DEPOT_DOWNLOADER_PATH, [`-app ${args.app}`, `-depot ${args.depot}`, `-manifest ${args.manifest}`, `-username ${args.username}`, `-dir ${args.folder}`, args.stay ? `-remember-password` : ''], {shell: true, cwd: args.cwd}); + + PROCESS.stdout.on('data', data => { + + const out: string[] = data.toString().split('|'); + console.log(out); + + if(out[0] === "[Progress]"){ event.reply('bs-download.progress', out[1]); } + else if(out[0] === "[Password]" || out[0].includes('[Password]')){ event.reply('bs-download.ask-password'); } + else if(out[0] === "[any]"){ event.reply('bs-download.progress', out); } + + }); + + PROCESS.stderr.on('data', (data) => {console.log(data.toString())}); +}); + +ipcMain.on('bs-download.send-input', async (event, value: string) => { + if(PROCESS){ PROCESS.stdin.write(`${value}\n`); } +}); diff --git a/src/main/ipcs/custom-ipcs.ts b/src/main/ipcs/custom-ipcs.ts new file mode 100644 index 00000000..d2a985dd --- /dev/null +++ b/src/main/ipcs/custom-ipcs.ts @@ -0,0 +1 @@ +import './bs-download-ipcs'; \ No newline at end of file diff --git a/src/main/main.ts b/src/main/main.ts index dcdf5293..2f738d9e 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -135,3 +135,5 @@ app }); }) .catch(console.log); + + import './ipcs/custom-ipcs'; diff --git a/src/main/preload.ts b/src/main/preload.ts index 88fa085b..bc549cfe 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -1,6 +1,8 @@ import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron'; -export type Channels = 'ipc-example'; +export type Channels = 'bs-download.start'|'bs-download.send-input'; + +export type ReplyChannels = 'bs-download.ask-password'; contextBridge.exposeInMainWorld('electron', { ipcRenderer: { diff --git a/src/main/utils.ts b/src/main/utils.ts new file mode 100644 index 00000000..106f2317 --- /dev/null +++ b/src/main/utils.ts @@ -0,0 +1,4 @@ +export function createFolderIfNotExist(path: string){ + const [existsSync, mkdirSync] = [require('fs').existsSync, require('fs').mkdirSync]; + if (!existsSync(path)){ mkdirSync(path); } +} \ No newline at end of file diff --git a/src/renderer/index.tsx b/src/renderer/index.tsx index a96350ee..5f5d8dee 100644 --- a/src/renderer/index.tsx +++ b/src/renderer/index.tsx @@ -1,13 +1,13 @@ import { createRoot } from 'react-dom/client'; import App from './App'; +import { InitDownloadInfoInterface } from 'main/ipcs/bs-download-ipcs'; const container = document.getElementById('root')!; const root = createRoot(container); root.render(); -// calling IPC exposed from preload script -window.electron.ipcRenderer.once('ipc-example', (arg) => { - // eslint-disable-next-line no-console - console.log(arg); -}); -window.electron.ipcRenderer.sendMessage('ipc-example', ['ping']); +setTimeout(() => { + window.electron.ipcRenderer.sendMessage('bs-download.start', {app: '620980', depot: '620981', manifest: '6222769774084748916', stay: true, username: 'lekilleur618', folder: 'test2', cwd: 'C:\\test'} as InitDownloadInfoInterface); +}, 5000); + +window.electron.ipcRenderer.on('bs-download.ask-password', () => console.log('omg popup password')); diff --git a/src/renderer/preload.d.ts b/src/renderer/preload.d.ts index 797d2759..b8b7e9d0 100644 --- a/src/renderer/preload.d.ts +++ b/src/renderer/preload.d.ts @@ -1,15 +1,15 @@ -import { Channels } from 'main/preload'; +import { Channels, ReplyChannels } from 'main/preload'; declare global { interface Window { electron: { ipcRenderer: { - sendMessage(channel: Channels, args: unknown[]): void; + sendMessage(channel: Channels, args: any): void; on( - channel: string, - func: (...args: unknown[]) => void + channel: ReplyChannels, + func: (...args: any) => void ): (() => void) | undefined; - once(channel: string, func: (...args: unknown[]) => void): void; + once(channel: ReplyChannels, func: (...args: any) => void): void; }; }; }