mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2026-01-30 19:15:17 +01:00
Compare commits
8 Commits
bigpicture
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ad005161f | ||
|
|
cc086a9f16 | ||
|
|
f41df6531c | ||
|
|
28d7a741c1 | ||
|
|
490a689497 | ||
|
|
84f4210479 | ||
|
|
a2d1a989e0 | ||
|
|
83d2301056 |
72
.github/workflows/release.yml
vendored
72
.github/workflows/release.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: 'publish'
|
name: "publish"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch: {}
|
workflow_dispatch: {}
|
||||||
@@ -18,16 +18,16 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- platform: 'macos-latest' # for Arm based macs (M1 and above).
|
- platform: "macos-14" # for Arm based macs (M1 and above).
|
||||||
args: '--target aarch64-apple-darwin'
|
args: "--target aarch64-apple-darwin"
|
||||||
- platform: 'macos-latest' # for Intel based macs.
|
- platform: "macos-14" # for Intel based macs.
|
||||||
args: '--target x86_64-apple-darwin'
|
args: "--target x86_64-apple-darwin"
|
||||||
- platform: 'ubuntu-22.04' # for Tauri v1 you could replace this with ubuntu-20.04.
|
- platform: "ubuntu-22.04" # for Tauri v1 you could replace this with ubuntu-20.04.
|
||||||
args: ''
|
args: ""
|
||||||
- platform: 'ubuntu-22.04-arm'
|
- platform: "ubuntu-22.04-arm"
|
||||||
args: '--target aarch64-unknown-linux-gnu'
|
args: "--target aarch64-unknown-linux-gnu"
|
||||||
- platform: 'windows-latest'
|
- platform: "windows-latest"
|
||||||
args: ''
|
args: ""
|
||||||
|
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
steps:
|
steps:
|
||||||
@@ -36,16 +36,29 @@ jobs:
|
|||||||
submodules: true
|
submodules: true
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: setup pnpm
|
||||||
|
uses: pnpm/action-setup@v4
|
||||||
|
with:
|
||||||
|
version: 10
|
||||||
|
run_install: false
|
||||||
|
|
||||||
- name: setup node
|
- name: setup node
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: lts/*
|
node-version: lts/*
|
||||||
|
cache: pnpm
|
||||||
|
|
||||||
|
|
||||||
- name: install Rust nightly
|
- name: install Rust nightly
|
||||||
uses: dtolnay/rust-toolchain@nightly
|
uses: dtolnay/rust-toolchain@nightly
|
||||||
with:
|
with:
|
||||||
# Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds.
|
# Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds.
|
||||||
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
|
targets: ${{ matrix.platform == 'macos-14' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
|
||||||
|
|
||||||
|
- name: Rust cache
|
||||||
|
uses: swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
workspaces: './src-tauri -> target'
|
||||||
|
|
||||||
- name: install dependencies (ubuntu only)
|
- name: install dependencies (ubuntu only)
|
||||||
if: matrix.platform == 'ubuntu-22.04' || matrix.platform == 'ubuntu-22.04-arm' # This must match the platform value defined above.
|
if: matrix.platform == 'ubuntu-22.04' || matrix.platform == 'ubuntu-22.04-arm' # This must match the platform value defined above.
|
||||||
@@ -54,9 +67,8 @@ jobs:
|
|||||||
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf xdg-utils
|
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf xdg-utils
|
||||||
# webkitgtk 4.0 is for Tauri v1 - webkitgtk 4.1 is for Tauri v2.
|
# webkitgtk 4.0 is for Tauri v1 - webkitgtk 4.1 is for Tauri v2.
|
||||||
|
|
||||||
|
|
||||||
- name: Import Apple Developer Certificate
|
- name: Import Apple Developer Certificate
|
||||||
if: matrix.platform == 'macos-latest'
|
if: matrix.platform == 'macos-14'
|
||||||
env:
|
env:
|
||||||
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
|
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
|
||||||
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
|
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
|
||||||
@@ -67,18 +79,30 @@ jobs:
|
|||||||
security default-keychain -s build.keychain
|
security default-keychain -s build.keychain
|
||||||
security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
|
security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
|
||||||
security set-keychain-settings -t 3600 -u build.keychain
|
security set-keychain-settings -t 3600 -u build.keychain
|
||||||
|
|
||||||
curl https://droposs.org/drop.crt --output drop.pem
|
|
||||||
sudo security authorizationdb write com.apple.trust-settings.user allow
|
echo "Created keychain"
|
||||||
security add-trusted-cert -r trustRoot -k build.keychain -p codeSign -u -1 drop.pem
|
|
||||||
sudo security authorizationdb remove com.apple.trust-settings.user
|
curl https://droposs.org/drop.der --output drop.der
|
||||||
|
|
||||||
|
# swiftc libs/appletrust/add-certificate.swift
|
||||||
|
# ./add-certificate drop.der
|
||||||
|
# rm add-certificate
|
||||||
|
|
||||||
|
# echo "Added certificate to keychain using swift util"
|
||||||
|
|
||||||
|
## Script is equivalent to:
|
||||||
|
sudo security authorizationdb write com.apple.trust-settings.admin allow
|
||||||
|
sudo security add-trusted-cert -d -r trustRoot -k build.keychain -p codeSign -u -1 drop.der
|
||||||
|
sudo security authorizationdb remove com.apple.trust-settings.admin
|
||||||
|
|
||||||
security import certificate.p12 -k build.keychain -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
|
security import certificate.p12 -k build.keychain -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
|
||||||
|
echo "Imported certificate"
|
||||||
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" build.keychain
|
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" build.keychain
|
||||||
security find-identity -v -p codesigning build.keychain
|
security find-identity -v -p codesigning build.keychain
|
||||||
|
|
||||||
- name: Verify Certificate
|
- name: Verify Certificate
|
||||||
if: matrix.platform == 'macos-latest'
|
if: matrix.platform == 'macos-14'
|
||||||
run: |
|
run: |
|
||||||
CERT_INFO=$(security find-identity -v -p codesigning build.keychain | grep "Drop OSS")
|
CERT_INFO=$(security find-identity -v -p codesigning build.keychain | grep "Drop OSS")
|
||||||
CERT_ID=$(echo "$CERT_INFO" | awk -F'"' '{print $2}')
|
CERT_ID=$(echo "$CERT_INFO" | awk -F'"' '{print $2}')
|
||||||
@@ -86,7 +110,7 @@ jobs:
|
|||||||
echo "Certificate imported. Using identity: $CERT_ID"
|
echo "Certificate imported. Using identity: $CERT_ID"
|
||||||
|
|
||||||
- name: install frontend dependencies
|
- name: install frontend dependencies
|
||||||
run: yarn install # change this to npm, pnpm or bun depending on which one you use.
|
run: pnpm install # change this to npm, pnpm or bun depending on which one you use.
|
||||||
|
|
||||||
- uses: tauri-apps/tauri-action@v0
|
- uses: tauri-apps/tauri-action@v0
|
||||||
env:
|
env:
|
||||||
@@ -97,8 +121,8 @@ jobs:
|
|||||||
NO_STRIP: true
|
NO_STRIP: true
|
||||||
with:
|
with:
|
||||||
tagName: v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
|
tagName: v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
|
||||||
releaseName: 'Auto-release v__VERSION__'
|
releaseName: "Auto-release v__VERSION__"
|
||||||
releaseBody: 'See the assets to download this version and install. This release was created automatically.'
|
releaseBody: "See the assets to download this version and install. This release was created automatically."
|
||||||
releaseDraft: false
|
releaseDraft: false
|
||||||
prerelease: true
|
prerelease: true
|
||||||
args: ${{ matrix.args }}
|
args: ${{ matrix.args }}
|
||||||
|
|||||||
2
.gitlab-ci-local/.gitignore
vendored
2
.gitlab-ci-local/.gitignore
vendored
@@ -1,2 +0,0 @@
|
|||||||
*
|
|
||||||
!.gitignore
|
|
||||||
@@ -40,10 +40,10 @@ for (const view of views) {
|
|||||||
process.chdir(`./${view}`);
|
process.chdir(`./${view}`);
|
||||||
|
|
||||||
loggerChild.info(`Install deps for "${view}"`);
|
loggerChild.info(`Install deps for "${view}"`);
|
||||||
await spawn("yarn");
|
await spawn("pnpm install");
|
||||||
|
|
||||||
loggerChild.info(`Building "${view}"`);
|
loggerChild.info(`Building "${view}"`);
|
||||||
await spawn("yarn build", {
|
await spawn("pnpm run build", {
|
||||||
env: { ...process.env, NUXT_APP_BASE_URL: `/${view}/` },
|
env: { ...process.env, NUXT_APP_BASE_URL: `/${view}/` },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
72
libs/appletrust/add-certificate.swift
Normal file
72
libs/appletrust/add-certificate.swift
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import Foundation
|
||||||
|
import Security
|
||||||
|
|
||||||
|
enum SecurityError: Error {
|
||||||
|
case generalError
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteCertificateFromKeyChain(_ certificateLabel: String) -> Bool {
|
||||||
|
let delQuery: [NSString: Any] = [
|
||||||
|
kSecClass: kSecClassCertificate,
|
||||||
|
kSecAttrLabel: certificateLabel,
|
||||||
|
]
|
||||||
|
let delStatus: OSStatus = SecItemDelete(delQuery as CFDictionary)
|
||||||
|
|
||||||
|
return delStatus == errSecSuccess
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveCertificateToKeyChain(_ certificate: SecCertificate, certificateLabel: String) throws {
|
||||||
|
SecKeychainSetPreferenceDomain(SecPreferencesDomain.system)
|
||||||
|
deleteCertificateFromKeyChain(certificateLabel)
|
||||||
|
|
||||||
|
let setQuery: [NSString: AnyObject] = [
|
||||||
|
kSecClass: kSecClassCertificate,
|
||||||
|
kSecValueRef: certificate,
|
||||||
|
kSecAttrLabel: certificateLabel as AnyObject,
|
||||||
|
kSecAttrAccessible: kSecAttrAccessibleWhenUnlocked,
|
||||||
|
kSecAttrCanSign: true as AnyObject,
|
||||||
|
]
|
||||||
|
let addStatus: OSStatus = SecItemAdd(setQuery as CFDictionary, nil)
|
||||||
|
|
||||||
|
guard addStatus == errSecSuccess else {
|
||||||
|
throw SecurityError.generalError
|
||||||
|
}
|
||||||
|
|
||||||
|
var status = SecTrustSettingsSetTrustSettings(certificate, SecTrustSettingsDomain.admin, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCertificateFromString(stringData: String) throws -> SecCertificate {
|
||||||
|
if let data = NSData(base64Encoded: stringData, options: NSData.Base64DecodingOptions.ignoreUnknownCharacters) {
|
||||||
|
if let certificate = SecCertificateCreateWithData(kCFAllocatorDefault, data) {
|
||||||
|
return certificate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw SecurityError.generalError
|
||||||
|
}
|
||||||
|
|
||||||
|
if CommandLine.arguments.count != 2 {
|
||||||
|
print("Usage: \(CommandLine.arguments[0]) [cert.file]")
|
||||||
|
print("Usage: \(CommandLine.arguments[0]) --version")
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CommandLine.arguments[1] == "--version") {
|
||||||
|
let version = "dev"
|
||||||
|
print(version)
|
||||||
|
exit(0)
|
||||||
|
} else {
|
||||||
|
let fileURL = URL(fileURLWithPath: CommandLine.arguments[1])
|
||||||
|
do {
|
||||||
|
let certData = try Data(contentsOf: fileURL)
|
||||||
|
let certificate = SecCertificateCreateWithData(nil, certData as CFData)
|
||||||
|
if certificate != nil {
|
||||||
|
try? saveCertificateToKeyChain(certificate!, certificateLabel: "DropOSS")
|
||||||
|
exit(0)
|
||||||
|
} else {
|
||||||
|
print("ERROR: Unknown error while reading the \(CommandLine.arguments[1]) file.")
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
print("ERROR: Unexpected error while reading the \(CommandLine.arguments[1]) file. \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit(1)
|
||||||
Submodule libs/drop-base updated: 04125e89be...14f4e3e20b
14
main/app.vue
14
main/app.vue
@@ -7,7 +7,16 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import "~/composables/downloads.js";
|
||||||
|
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { useAppState } from "./composables/app-state.js";
|
||||||
|
import {
|
||||||
|
initialNavigation,
|
||||||
|
setupHooks,
|
||||||
|
} from "./composables/state-navigation.js";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import type { AppState } from "./types.js";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -29,9 +38,8 @@ async function fetchState() {
|
|||||||
}
|
}
|
||||||
await fetchState();
|
await fetchState();
|
||||||
|
|
||||||
// This is inefficient but apparently we do it lol
|
listen("update_state", (event) => {
|
||||||
router.beforeEach(async () => {
|
state.value = event.payload as AppState;
|
||||||
await fetchState();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setupHooks();
|
setupHooks();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ html,
|
|||||||
body {
|
body {
|
||||||
-ms-overflow-style: none; /* IE and Edge /
|
-ms-overflow-style: none; /* IE and Edge /
|
||||||
scrollbar-width: none; / Firefox */
|
scrollbar-width: none; / Firefox */
|
||||||
|
overscroll-behavior: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hide scrollbar for Chrome, Safari and Opera */
|
/* Hide scrollbar for Chrome, Safari and Opera */
|
||||||
|
|||||||
106
main/components/DependencyRequiredModal.vue
Normal file
106
main/components/DependencyRequiredModal.vue
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<template>
|
||||||
|
<ModalTemplate :model-value="true">
|
||||||
|
<template #default
|
||||||
|
><div class="flex items-start gap-x-3">
|
||||||
|
<img :src="useObject(game.mIconObjectId)" class="size-12" />
|
||||||
|
<div class="mt-3 text-center sm:mt-0 sm:text-left">
|
||||||
|
<h3 class="text-base font-semibold text-zinc-100">
|
||||||
|
Missing required dependency "{{ game.mName }}"
|
||||||
|
</h3>
|
||||||
|
<div class="mt-2">
|
||||||
|
<p class="text-sm text-zinc-400">
|
||||||
|
To launch this game, you need to have "{{ game.mName }}" ({{
|
||||||
|
version.displayName ?? version.versionPath
|
||||||
|
}}) installed.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<InstallDirectorySelector
|
||||||
|
:install-dirs="installDirs"
|
||||||
|
v-model="installDir"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div v-if="installError" class="mt-1 rounded-md bg-red-600/10 p-4">
|
||||||
|
<div class="flex">
|
||||||
|
<div class="flex-shrink-0">
|
||||||
|
<XCircleIcon class="h-5 w-5 text-red-600" aria-hidden="true" />
|
||||||
|
</div>
|
||||||
|
<div class="ml-3">
|
||||||
|
<h3 class="text-sm font-medium text-red-600">
|
||||||
|
{{ installError }}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template #buttons>
|
||||||
|
<LoadingButton
|
||||||
|
@click="() => install()"
|
||||||
|
:loading="installLoading"
|
||||||
|
:disabled="installLoading"
|
||||||
|
type="submit"
|
||||||
|
class="ml-2 w-full sm:w-fit"
|
||||||
|
>
|
||||||
|
Install
|
||||||
|
</LoadingButton>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="mt-3 inline-flex w-full justify-center rounded-md bg-zinc-800 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 hover:bg-zinc-900 sm:mt-0 sm:w-auto"
|
||||||
|
@click="cancel"
|
||||||
|
ref="cancelButtonRef"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</ModalTemplate>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { XCircleIcon } from "@heroicons/vue/24/solid";
|
||||||
|
|
||||||
|
const model = defineModel<{ gameId: string; versionId: string }>({
|
||||||
|
required: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { game, status } = await useGame(model.value.gameId);
|
||||||
|
|
||||||
|
const versionOptions = await invoke<Array<VersionOption>>(
|
||||||
|
"fetch_game_version_options",
|
||||||
|
{
|
||||||
|
gameId: game.id,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const version = versionOptions.find(
|
||||||
|
(v) => v.versionId === model.value.versionId
|
||||||
|
)!;
|
||||||
|
|
||||||
|
const installDirs = await invoke<string[]>("fetch_download_dir_stats");
|
||||||
|
const installDir = ref(0);
|
||||||
|
|
||||||
|
function cancel() {
|
||||||
|
// @ts-expect-error
|
||||||
|
model.value = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const installError = ref<string | undefined>();
|
||||||
|
const installLoading = ref(false);
|
||||||
|
|
||||||
|
async function install() {
|
||||||
|
try {
|
||||||
|
installLoading.value = true;
|
||||||
|
await invoke("download_game", {
|
||||||
|
gameId: game.id,
|
||||||
|
versionId: model.value.versionId,
|
||||||
|
installDir: installDir.value,
|
||||||
|
targetPlatform: version.platform,
|
||||||
|
});
|
||||||
|
cancel();
|
||||||
|
} catch (error) {
|
||||||
|
installError.value = (error as string).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
installLoading.value = false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -2,7 +2,9 @@
|
|||||||
<div class="h-16 bg-zinc-950 flex flex-row justify-between">
|
<div class="h-16 bg-zinc-950 flex flex-row justify-between">
|
||||||
<div class="flex flex-row grow items-center pl-5 pr-2 py-3">
|
<div class="flex flex-row grow items-center pl-5 pr-2 py-3">
|
||||||
<div class="inline-flex items-center gap-x-10">
|
<div class="inline-flex items-center gap-x-10">
|
||||||
<Wordmark class="h-8 mb-0.5" />
|
<NuxtLink to="/store">
|
||||||
|
<Wordmark class="h-8 mb-0.5" />
|
||||||
|
</NuxtLink>
|
||||||
<nav class="inline-flex items-center mt-0.5">
|
<nav class="inline-flex items-center mt-0.5">
|
||||||
<ol class="inline-flex items-center gap-x-6">
|
<ol class="inline-flex items-center gap-x-6">
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
@@ -40,7 +42,7 @@
|
|||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<WindowControl />
|
<WindowControl />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/vue";
|
|||||||
import { ChevronDownIcon } from "@heroicons/vue/16/solid";
|
import { ChevronDownIcon } from "@heroicons/vue/16/solid";
|
||||||
import type { NavigationItem } from "../types";
|
import type { NavigationItem } from "../types";
|
||||||
import HeaderWidget from "./HeaderWidget.vue";
|
import HeaderWidget from "./HeaderWidget.vue";
|
||||||
|
import { useAppState } from "~/composables/app-state";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
const open = ref(false);
|
const open = ref(false);
|
||||||
|
|||||||
87
main/components/InstallDirectorySelector.vue
Normal file
87
main/components/InstallDirectorySelector.vue
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<template>
|
||||||
|
<Listbox as="div" v-model="installDir">
|
||||||
|
<ListboxLabel class="block text-sm/6 font-medium text-zinc-100"
|
||||||
|
>Install to</ListboxLabel
|
||||||
|
>
|
||||||
|
<div class="relative mt-2">
|
||||||
|
<ListboxButton
|
||||||
|
class="relative w-full cursor-default rounded-md bg-zinc-800 py-1.5 pl-3 pr-10 text-left text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 focus:outline-none focus:ring-2 focus:ring-blue-600 sm:text-sm/6"
|
||||||
|
>
|
||||||
|
<span class="block truncate">{{ installDirs[installDir] }}</span>
|
||||||
|
<span
|
||||||
|
class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2"
|
||||||
|
>
|
||||||
|
<ChevronUpDownIcon class="h-5 w-5 text-gray-400" aria-hidden="true" />
|
||||||
|
</span>
|
||||||
|
</ListboxButton>
|
||||||
|
|
||||||
|
<transition
|
||||||
|
leave-active-class="transition ease-in duration-100"
|
||||||
|
leave-from-class="opacity-100"
|
||||||
|
leave-to-class="opacity-0"
|
||||||
|
>
|
||||||
|
<ListboxOptions
|
||||||
|
class="absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md bg-zinc-900 py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm"
|
||||||
|
>
|
||||||
|
<ListboxOption
|
||||||
|
as="template"
|
||||||
|
v-for="(dir, dirIdx) in installDirs"
|
||||||
|
:key="dir"
|
||||||
|
:value="dirIdx"
|
||||||
|
v-slot="{ active, selected }"
|
||||||
|
>
|
||||||
|
<li
|
||||||
|
:class="[
|
||||||
|
active ? 'bg-blue-600 text-white' : 'text-zinc-300',
|
||||||
|
'relative cursor-default select-none py-2 pl-3 pr-9',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
:class="[
|
||||||
|
selected ? 'font-semibold text-zinc-100' : 'font-normal',
|
||||||
|
'block truncate',
|
||||||
|
]"
|
||||||
|
>{{ dir }}</span
|
||||||
|
>
|
||||||
|
|
||||||
|
<span
|
||||||
|
v-if="selected"
|
||||||
|
:class="[
|
||||||
|
active ? 'text-white' : 'text-blue-600',
|
||||||
|
'absolute inset-y-0 right-0 flex items-center pr-4',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<CheckIcon class="h-5 w-5" aria-hidden="true" />
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ListboxOption>
|
||||||
|
</ListboxOptions>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
<div class="text-zinc-400 text-sm mt-2">
|
||||||
|
Add more install directories in
|
||||||
|
<PageWidget to="/settings/downloads">
|
||||||
|
<WrenchIcon class="size-3" />
|
||||||
|
Settings
|
||||||
|
</PageWidget>
|
||||||
|
</div>
|
||||||
|
</Listbox>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Listbox,
|
||||||
|
ListboxButton,
|
||||||
|
ListboxLabel,
|
||||||
|
ListboxOption,
|
||||||
|
ListboxOptions,
|
||||||
|
} from "@headlessui/vue";
|
||||||
|
import {
|
||||||
|
CheckIcon,
|
||||||
|
ChevronUpDownIcon,
|
||||||
|
WrenchIcon,
|
||||||
|
} from "@heroicons/vue/20/solid";
|
||||||
|
|
||||||
|
const installDir = defineModel<number>({ required: true });
|
||||||
|
const { installDirs } = defineProps<{ installDirs: string[] }>();
|
||||||
|
</script>
|
||||||
@@ -27,12 +27,12 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<TransitionGroup name="list" tag="ul" class="flex flex-col gap-y-1.5">
|
<TransitionGroup name="list" tag="ul" class="flex flex-col gap-y-1.5 h-full">
|
||||||
<Disclosure
|
<Disclosure
|
||||||
as="div"
|
as="div"
|
||||||
v-for="(nav, navIndex) in filteredNavigation"
|
v-for="(nav, navIndex) in filteredNavigation"
|
||||||
:key="nav.id"
|
:key="nav.id"
|
||||||
class="first:pt-0 last:pb-0"
|
:class="['first:pt-0 last:pb-0', nav.tools ? 'mt-auto' : '']"
|
||||||
v-slot="{ open }"
|
v-slot="{ open }"
|
||||||
:default-open="nav.deft"
|
:default-open="nav.deft"
|
||||||
>
|
>
|
||||||
@@ -43,9 +43,12 @@
|
|||||||
<span class="text-sm font-semibold font-display">{{
|
<span class="text-sm font-semibold font-display">{{
|
||||||
nav.name
|
nav.name
|
||||||
}}</span>
|
}}</span>
|
||||||
<span class="ml-6 flex h-7 items-center">
|
<span class="ml-6 relative flex size-4">
|
||||||
<PlusSmallIcon v-if="!open" class="size-6" aria-hidden="true" />
|
<MinusIcon class="absolute inset-0 size-4" aria-hidden="true" />
|
||||||
<MinusSmallIcon v-else class="size-6" aria-hidden="true" />
|
<MinusIcon
|
||||||
|
:class="[ !open ? 'rotate-90' : 'rotate-0', 'transition-all absolute inset-0 size-4']"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
</span>
|
</span>
|
||||||
</DisclosureButton>
|
</DisclosureButton>
|
||||||
</dt>
|
</dt>
|
||||||
@@ -58,8 +61,8 @@
|
|||||||
currentNavigation == item.id
|
currentNavigation == item.id
|
||||||
? 'bg-zinc-800 text-zinc-100 shadow-md shadow-zinc-950/20'
|
? 'bg-zinc-800 text-zinc-100 shadow-md shadow-zinc-950/20'
|
||||||
: item.isInstalled.value
|
: item.isInstalled.value
|
||||||
? 'text-zinc-300 hover:bg-zinc-800/90 hover:text-zinc-200'
|
? 'text-zinc-300 hover:bg-zinc-800/90 hover:text-zinc-200'
|
||||||
: 'text-zinc-500 hover:bg-zinc-800/70 hover:text-zinc-300',
|
: 'text-zinc-500 hover:bg-zinc-800/70 hover:text-zinc-300',
|
||||||
]"
|
]"
|
||||||
:href="item.route"
|
:href="item.route"
|
||||||
>
|
>
|
||||||
@@ -69,14 +72,12 @@
|
|||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
class="size-6 object-cover bg-zinc-900 rounded transition-all duration-300 shadow-sm"
|
class="size-6 object-cover bg-zinc-900 rounded transition-all duration-300 shadow-sm"
|
||||||
:src="icons[item.id]"
|
:src="useObject(item.icon)"
|
||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-x-2">
|
<div class="truncate inline-flex items-center gap-x-2">
|
||||||
<p
|
<p class="text-sm whitespace-nowrap font-display font-semibold">
|
||||||
class="text-sm whitespace-nowrap font-display font-semibold"
|
|
||||||
>
|
|
||||||
{{ item.label }}
|
{{ item.label }}
|
||||||
</p>
|
</p>
|
||||||
<p
|
<p
|
||||||
@@ -125,8 +126,8 @@ import { Disclosure, DisclosureButton, DisclosurePanel } from "@headlessui/vue";
|
|||||||
import {
|
import {
|
||||||
ArrowPathIcon,
|
ArrowPathIcon,
|
||||||
MagnifyingGlassIcon,
|
MagnifyingGlassIcon,
|
||||||
MinusSmallIcon,
|
MinusIcon,
|
||||||
PlusSmallIcon,
|
PlusIcon,
|
||||||
} from "@heroicons/vue/20/solid";
|
} from "@heroicons/vue/20/solid";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import {
|
import {
|
||||||
@@ -143,7 +144,7 @@ const gameStatusTextStyle: { [key in GameStatusEnum]: string } = {
|
|||||||
[GameStatusEnum.Installed]: "text-green-500",
|
[GameStatusEnum.Installed]: "text-green-500",
|
||||||
[GameStatusEnum.Downloading]: "text-zinc-400",
|
[GameStatusEnum.Downloading]: "text-zinc-400",
|
||||||
[GameStatusEnum.Validating]: "text-blue-300",
|
[GameStatusEnum.Validating]: "text-blue-300",
|
||||||
[GameStatusEnum.Running]: "text-green-500",
|
[GameStatusEnum.Running]: "text-blue-500",
|
||||||
[GameStatusEnum.Remote]: "text-zinc-700",
|
[GameStatusEnum.Remote]: "text-zinc-700",
|
||||||
[GameStatusEnum.Queued]: "text-zinc-400",
|
[GameStatusEnum.Queued]: "text-zinc-400",
|
||||||
[GameStatusEnum.Updating]: "text-zinc-400",
|
[GameStatusEnum.Updating]: "text-zinc-400",
|
||||||
@@ -172,49 +173,76 @@ const loading = ref(false);
|
|||||||
const games: {
|
const games: {
|
||||||
[key: string]: { game: Game; status: Ref<GameStatus, GameStatus> };
|
[key: string]: { game: Game; status: Ref<GameStatus, GameStatus> };
|
||||||
} = {};
|
} = {};
|
||||||
const icons: { [key: string]: string } = {};
|
|
||||||
|
|
||||||
const collections: Ref<Collection[]> = ref([]);
|
const collections: Ref<Collection[]> = ref([]);
|
||||||
|
|
||||||
async function calculateGames(clearAll = false, forceRefresh = false) {
|
async function calculateGames(clearAll = false, forceRefresh = false) {
|
||||||
|
try {
|
||||||
|
await calculateGamesLogic(clearAll, forceRefresh);
|
||||||
|
} catch (e) {
|
||||||
|
createModal(
|
||||||
|
ModalType.Notification,
|
||||||
|
{
|
||||||
|
title: "Failed to fetch library",
|
||||||
|
description: `Drop encountered an error while fetching your library: ${e}`,
|
||||||
|
},
|
||||||
|
(_, c) => c(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
type FetchLibraryResponse = {
|
||||||
|
library: Game[];
|
||||||
|
collections: Collection[];
|
||||||
|
other: Game[];
|
||||||
|
};
|
||||||
|
|
||||||
|
async function calculateGamesLogic(clearAll = false, forceRefresh = false) {
|
||||||
if (clearAll) {
|
if (clearAll) {
|
||||||
collections.value = [];
|
collections.value = [];
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
}
|
}
|
||||||
// If we update immediately, the navigation gets re-rendered before we
|
// If we update immediately, the navigation gets re-rendered before we
|
||||||
// add all the necessary state, and it freaks tf out
|
// add all the necessary state, and it freaks tf out
|
||||||
const newGames = await invoke<Game[]>("fetch_library", {
|
const library = await invoke<FetchLibraryResponse>("fetch_library", {
|
||||||
hardRefresh: forceRefresh,
|
|
||||||
});
|
|
||||||
const otherCollections = await invoke<Collection[]>("fetch_collections", {
|
|
||||||
hardRefresh: forceRefresh,
|
hardRefresh: forceRefresh,
|
||||||
});
|
});
|
||||||
const allGames = [
|
const allGames = [
|
||||||
...newGames,
|
...library.library,
|
||||||
...otherCollections
|
...library.collections
|
||||||
.map((e) => e.entries)
|
.map((e) => e.entries)
|
||||||
.flat()
|
.flat()
|
||||||
.map((e) => e.game),
|
.map((e) => e.game),
|
||||||
|
...library.other,
|
||||||
].filter((v, i, a) => a.indexOf(v) === i);
|
].filter((v, i, a) => a.indexOf(v) === i);
|
||||||
|
|
||||||
for (const game of allGames) {
|
for (const game of allGames) {
|
||||||
if (games[game.id]) continue;
|
if (games[game.id]) continue;
|
||||||
games[game.id] = await useGame(game.id);
|
games[game.id] = await useGame(game.id);
|
||||||
}
|
}
|
||||||
for (const game of allGames) {
|
|
||||||
if (icons[game.id]) continue;
|
|
||||||
icons[game.id] = await useObject(game.mIconObjectId);
|
|
||||||
}
|
|
||||||
|
|
||||||
const libraryCollection = {
|
const libraryCollection = {
|
||||||
id: "library",
|
id: "library",
|
||||||
name: "Library",
|
name: "Library",
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
entries: newGames.map((e) => ({ gameId: e.id, game: e })),
|
entries: library.library.map((e) => ({ gameId: e.id, game: e })),
|
||||||
|
} satisfies Collection;
|
||||||
|
|
||||||
|
const otherCollection = {
|
||||||
|
id: "other",
|
||||||
|
name: "Tools & Launchers",
|
||||||
|
isDefault: false,
|
||||||
|
isTools: true,
|
||||||
|
entries: library.other.map((v) => ({ gameId: v.id, game: v })),
|
||||||
} satisfies Collection;
|
} satisfies Collection;
|
||||||
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
collections.value = [libraryCollection, ...otherCollections];
|
collections.value = [
|
||||||
|
libraryCollection,
|
||||||
|
...library.collections,
|
||||||
|
...(library.other.length > 0 ? [otherCollection] : []),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait up to 300 ms for the library to load, otherwise
|
// Wait up to 300 ms for the library to load, otherwise
|
||||||
@@ -235,15 +263,17 @@ const navigation = computed(() =>
|
|||||||
const status = games[game.id].status;
|
const status = games[game.id].status;
|
||||||
|
|
||||||
const isInstalled = computed(
|
const isInstalled = computed(
|
||||||
() => status.value.type != GameStatusEnum.Remote
|
() => status.value.type != GameStatusEnum.Remote,
|
||||||
);
|
);
|
||||||
|
|
||||||
const item = {
|
const item = {
|
||||||
label: game.mName,
|
label: game.mName,
|
||||||
route: `/library/${game.id}`,
|
route: `/library/${game.id}`,
|
||||||
prefix: `/library/${game.id}`,
|
prefix: `/library/${game.id}`,
|
||||||
|
icon: game.mIconObjectId,
|
||||||
isInstalled,
|
isInstalled,
|
||||||
id: game.id,
|
id: game.id,
|
||||||
|
type: game.type,
|
||||||
};
|
};
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
@@ -252,9 +282,10 @@ const navigation = computed(() =>
|
|||||||
id: collection.id,
|
id: collection.id,
|
||||||
name: collection.name,
|
name: collection.name,
|
||||||
deft: collection.isDefault,
|
deft: collection.isDefault,
|
||||||
|
tools: collection.isTools ?? false,
|
||||||
items,
|
items,
|
||||||
};
|
};
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -277,7 +308,7 @@ const filteredNavigation = computed(() => {
|
|||||||
listen("update_library", async (event) => {
|
listen("update_library", async (event) => {
|
||||||
console.log("Updating library");
|
console.log("Updating library");
|
||||||
let oldNavigation = currentNavigation.value;
|
let oldNavigation = currentNavigation.value;
|
||||||
await calculateGames();
|
await calculateGames(false, true);
|
||||||
if (oldNavigation !== currentNavigation.value) {
|
if (oldNavigation !== currentNavigation.value) {
|
||||||
router.push("/library");
|
router.push("/library");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ArrowDownTrayIcon, CloudIcon } from "@heroicons/vue/20/solid";
|
import { ArrowDownTrayIcon, CloudIcon } from "@heroicons/vue/20/solid";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
|
async function checkOffline() {
|
||||||
|
const isOffline = await invoke("check_online");
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<button
|
||||||
|
@click="checkOffline"
|
||||||
class="transition inline-flex items-center rounded-sm px-4 py-1.5 bg-zinc-900 text-sm text-zinc-400 gap-x-2"
|
class="transition inline-flex items-center rounded-sm px-4 py-1.5 bg-zinc-900 text-sm text-zinc-400 gap-x-2"
|
||||||
>
|
>
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
@@ -13,5 +19,5 @@ import { ArrowDownTrayIcon, CloudIcon } from "@heroicons/vue/20/solid";
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
Offline
|
Offline
|
||||||
</div>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
7
main/components/PageWidget.vue
Normal file
7
main/components/PageWidget.vue
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<template>
|
||||||
|
<NuxtLink
|
||||||
|
class="inline-flex items-center gap-x-2 px-1 py-0.5 rounded bg-blue-900 text-zinc-100 hover:bg-blue-800"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</NuxtLink>
|
||||||
|
</template>
|
||||||
@@ -33,4 +33,18 @@ listen("update_stats", (event) => {
|
|||||||
stats.value = event.payload as StatsState;
|
stats.value = event.payload as StatsState;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useDownloadHistory = () => useState<Array<number>>('history', () => []);
|
export const useDownloadHistory = () => useState<Array<number>>('history', () => []);
|
||||||
|
|
||||||
|
export function formatKilobytes(bytes: number): string {
|
||||||
|
const units = ["K", "M", "G", "T", "P"];
|
||||||
|
let value = bytes;
|
||||||
|
let unitIndex = 0;
|
||||||
|
const scalar = 1000;
|
||||||
|
|
||||||
|
while (value >= scalar && unitIndex < units.length - 1) {
|
||||||
|
value /= scalar;
|
||||||
|
unitIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${value.toFixed(1)} ${units[unitIndex]}`;
|
||||||
|
}
|
||||||
@@ -43,19 +43,18 @@ export const useGame = async (gameId: string) => {
|
|||||||
gameStatusRegistry[gameId] = ref(parseStatus(data.status));
|
gameStatusRegistry[gameId] = ref(parseStatus(data.status));
|
||||||
|
|
||||||
listen(`update_game/${gameId}`, (event) => {
|
listen(`update_game/${gameId}`, (event) => {
|
||||||
console.log(event);
|
|
||||||
const payload: {
|
const payload: {
|
||||||
status: SerializedGameStatus;
|
status: SerializedGameStatus;
|
||||||
version?: GameVersion;
|
version?: GameVersion;
|
||||||
} = event.payload as any;
|
} = event.payload as any;
|
||||||
gameStatusRegistry[gameId].value = parseStatus(payload.status);
|
gameStatusRegistry[gameId].value = parseStatus(payload.status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I am not super happy about this.
|
* I am not super happy about this.
|
||||||
*
|
*
|
||||||
* This will mean that we will still have a version assigned if we have a game installed then uninstall it.
|
* This will mean that we will still have a version assigned if we have a game installed then uninstall it.
|
||||||
* It is necessary because a flag to check if we should overwrite seems excessive, and this function gets called
|
* It is necessary because a flag to check if we should overwrite seems excessive, and this function gets called
|
||||||
* on transient state updates.
|
* on transient state updates.
|
||||||
*/
|
*/
|
||||||
if (payload.version) {
|
if (payload.version) {
|
||||||
gameRegistry[gameId].version = payload.version;
|
gameRegistry[gameId].version = payload.version;
|
||||||
@@ -72,3 +71,23 @@ export const useGame = async (gameId: string) => {
|
|||||||
export type FrontendGameConfiguration = {
|
export type FrontendGameConfiguration = {
|
||||||
launchString: string;
|
launchString: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type LaunchResult =
|
||||||
|
| { result: "Success" }
|
||||||
|
| { result: "InstallRequired"; data: [string, string] };
|
||||||
|
|
||||||
|
export type VersionOption = {
|
||||||
|
versionId: string;
|
||||||
|
displayName?: string;
|
||||||
|
versionPath: string;
|
||||||
|
platform: string;
|
||||||
|
size: number;
|
||||||
|
requiredContent: Array<{
|
||||||
|
gameId: string;
|
||||||
|
versionId: string;
|
||||||
|
name: string;
|
||||||
|
iconObjectId: string;
|
||||||
|
shortDescription: string;
|
||||||
|
size: number;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
@@ -9,17 +9,14 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
ssr: false,
|
css: ["~/assets/main.scss"],
|
||||||
|
|
||||||
extends: ["../shared", "../libs/drop-base"],
|
ssr: false,
|
||||||
|
devtools: false,
|
||||||
|
|
||||||
|
extends: [["../libs/drop-base"]],
|
||||||
|
|
||||||
app: {
|
app: {
|
||||||
baseURL: "/main",
|
baseURL: "/main",
|
||||||
},
|
}
|
||||||
|
|
||||||
devtools: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "view",
|
"name": "view",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.3.3",
|
"version": "0.3.4",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nuxt generate",
|
"build": "nuxt generate",
|
||||||
@@ -13,7 +13,9 @@
|
|||||||
"@headlessui/vue": "^1.7.23",
|
"@headlessui/vue": "^1.7.23",
|
||||||
"@heroicons/vue": "^2.1.5",
|
"@heroicons/vue": "^2.1.5",
|
||||||
"@nuxtjs/tailwindcss": "^6.12.2",
|
"@nuxtjs/tailwindcss": "^6.12.2",
|
||||||
"@tauri-apps/api": "^2.7.0",
|
"@tauri-apps/api": "^2.9.1",
|
||||||
|
"@tauri-apps/plugin-os": "^2.3.2",
|
||||||
|
"@tauri-apps/plugin-shell": "^2.3.3",
|
||||||
"koa": "^2.16.1",
|
"koa": "^2.16.1",
|
||||||
"markdown-it": "^14.1.0",
|
"markdown-it": "^14.1.0",
|
||||||
"micromark": "^4.0.1",
|
"micromark": "^4.0.1",
|
||||||
@@ -32,6 +34,5 @@
|
|||||||
"tailwindcss": "^3.4.13",
|
"tailwindcss": "^3.4.13",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
"vue-tsc": "^2.2.10"
|
"vue-tsc": "^2.2.10"
|
||||||
},
|
}
|
||||||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,8 +170,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form class="space-y-6">
|
<div class="space-y-6">
|
||||||
<div v-if="versionOptions && versionOptions.length > 0">
|
<div v-if="versionOptions && versionOptions.length > 0 && currentVersionOption">
|
||||||
<Listbox as="div" v-model="installVersionIndex">
|
<Listbox as="div" v-model="installVersionIndex">
|
||||||
<ListboxLabel class="block text-sm/6 font-medium text-zinc-100"
|
<ListboxLabel class="block text-sm/6 font-medium text-zinc-100"
|
||||||
>Version</ListboxLabel
|
>Version</ListboxLabel
|
||||||
@@ -181,9 +181,16 @@
|
|||||||
class="relative w-full cursor-default rounded-md bg-zinc-800 py-1.5 pl-3 pr-10 text-left text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 focus:outline-none focus:ring-2 focus:ring-blue-600 sm:text-sm/6"
|
class="relative w-full cursor-default rounded-md bg-zinc-800 py-1.5 pl-3 pr-10 text-left text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 focus:outline-none focus:ring-2 focus:ring-blue-600 sm:text-sm/6"
|
||||||
>
|
>
|
||||||
<span class="block truncate"
|
<span class="block truncate"
|
||||||
>{{ versionOptions[installVersionIndex].versionName }}
|
>{{
|
||||||
|
currentVersionOption.displayName ||
|
||||||
|
currentVersionOption.versionPath
|
||||||
|
}}
|
||||||
on
|
on
|
||||||
{{ versionOptions[installVersionIndex].platform }}</span
|
{{ currentVersionOption.platform }} ({{
|
||||||
|
formatKilobytes(
|
||||||
|
currentVersionOption.size / 1024
|
||||||
|
)
|
||||||
|
}}B)</span
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2"
|
class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2"
|
||||||
@@ -206,7 +213,7 @@
|
|||||||
<ListboxOption
|
<ListboxOption
|
||||||
as="template"
|
as="template"
|
||||||
v-for="(version, versionIdx) in versionOptions"
|
v-for="(version, versionIdx) in versionOptions"
|
||||||
:key="version.versionName"
|
:key="version.versionId"
|
||||||
:value="versionIdx"
|
:value="versionIdx"
|
||||||
v-slot="{ active, selected }"
|
v-slot="{ active, selected }"
|
||||||
>
|
>
|
||||||
@@ -223,8 +230,12 @@
|
|||||||
: 'font-normal',
|
: 'font-normal',
|
||||||
'block truncate',
|
'block truncate',
|
||||||
]"
|
]"
|
||||||
>{{ version.versionName }} on
|
>{{ version.displayName || version.versionPath }} on
|
||||||
{{ version.platform }}</span
|
{{ version.platform }} ({{
|
||||||
|
formatKilobytes(
|
||||||
|
versionOptions[installVersionIndex].size / 1024
|
||||||
|
)
|
||||||
|
}}B)</span
|
||||||
>
|
>
|
||||||
|
|
||||||
<span
|
<span
|
||||||
@@ -281,82 +292,86 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="installDirs">
|
<div v-if="installDirs">
|
||||||
<Listbox as="div" v-model="installDir">
|
<InstallDirectorySelector
|
||||||
<ListboxLabel class="block text-sm/6 font-medium text-zinc-100"
|
:install-dirs="installDirs"
|
||||||
>Install to</ListboxLabel
|
v-model="installDir"
|
||||||
>
|
/>
|
||||||
<div class="relative mt-2">
|
|
||||||
<ListboxButton
|
|
||||||
class="relative w-full cursor-default rounded-md bg-zinc-800 py-1.5 pl-3 pr-10 text-left text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 focus:outline-none focus:ring-2 focus:ring-blue-600 sm:text-sm/6"
|
|
||||||
>
|
|
||||||
<span class="block truncate">{{
|
|
||||||
installDirs[installDir]
|
|
||||||
}}</span>
|
|
||||||
<span
|
|
||||||
class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2"
|
|
||||||
>
|
|
||||||
<ChevronUpDownIcon
|
|
||||||
class="h-5 w-5 text-gray-400"
|
|
||||||
aria-hidden="true"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</ListboxButton>
|
|
||||||
|
|
||||||
<transition
|
|
||||||
leave-active-class="transition ease-in duration-100"
|
|
||||||
leave-from-class="opacity-100"
|
|
||||||
leave-to-class="opacity-0"
|
|
||||||
>
|
|
||||||
<ListboxOptions
|
|
||||||
class="absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md bg-zinc-900 py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm"
|
|
||||||
>
|
|
||||||
<ListboxOption
|
|
||||||
as="template"
|
|
||||||
v-for="(dir, dirIdx) in installDirs"
|
|
||||||
:key="dir"
|
|
||||||
:value="dirIdx"
|
|
||||||
v-slot="{ active, selected }"
|
|
||||||
>
|
|
||||||
<li
|
|
||||||
:class="[
|
|
||||||
active ? 'bg-blue-600 text-white' : 'text-zinc-300',
|
|
||||||
'relative cursor-default select-none py-2 pl-3 pr-9',
|
|
||||||
]"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
:class="[
|
|
||||||
selected
|
|
||||||
? 'font-semibold text-zinc-100'
|
|
||||||
: 'font-normal',
|
|
||||||
'block truncate',
|
|
||||||
]"
|
|
||||||
>{{ dir }}</span
|
|
||||||
>
|
|
||||||
|
|
||||||
<span
|
|
||||||
v-if="selected"
|
|
||||||
:class="[
|
|
||||||
active ? 'text-white' : 'text-blue-600',
|
|
||||||
'absolute inset-y-0 right-0 flex items-center pr-4',
|
|
||||||
]"
|
|
||||||
>
|
|
||||||
<CheckIcon class="h-5 w-5" aria-hidden="true" />
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
</ListboxOption>
|
|
||||||
</ListboxOptions>
|
|
||||||
</transition>
|
|
||||||
</div>
|
|
||||||
<div class="text-zinc-400 text-sm mt-2">
|
|
||||||
Add more install directories in
|
|
||||||
<PageWidget to="/settings/downloads">
|
|
||||||
<WrenchIcon class="size-3" />
|
|
||||||
Settings
|
|
||||||
</PageWidget>
|
|
||||||
</div>
|
|
||||||
</Listbox>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
<div
|
||||||
|
v-if="
|
||||||
|
currentVersionOption?.requiredContent &&
|
||||||
|
currentVersionOption.requiredContent.length > 0
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<div class="border-b border-white/10 py-2">
|
||||||
|
<h3 class="text-sm font-semibold text-white">
|
||||||
|
Install additional dependencies?
|
||||||
|
</h3>
|
||||||
|
<p class="mt-1 text-xs text-gray-400">
|
||||||
|
This game requires additional content to run. Click the components
|
||||||
|
to automatically queue for download.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<ul role="list" class="mt-2 divide-y divide-white/5">
|
||||||
|
<li
|
||||||
|
v-for="content in currentVersionOption
|
||||||
|
.requiredContent"
|
||||||
|
:key="content.versionId"
|
||||||
|
:class="[
|
||||||
|
!installDepsDisabled[content.versionId]
|
||||||
|
? 'bg-zinc-950 ring-2 ring-zinc-800'
|
||||||
|
: '',
|
||||||
|
'rounded-lg relative flex justify-between px-2 py-3',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<div class="flex min-w-0 gap-x-2">
|
||||||
|
<img
|
||||||
|
class="size-12 flex-none"
|
||||||
|
:src="useObject(content.iconObjectId)"
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
<div class="min-w-0 flex-auto">
|
||||||
|
<p class="text-sm/6 font-semibold text-white">
|
||||||
|
<button
|
||||||
|
@click="
|
||||||
|
() =>
|
||||||
|
(installDepsDisabled[content.versionId] =
|
||||||
|
!installDepsDisabled[content.versionId])
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<span class="absolute inset-x-0 -top-px bottom-0"></span>
|
||||||
|
{{ content.name }}
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 flex text-xs/5 text-gray-400">
|
||||||
|
{{ content.shortDescription }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex shrink-0 items-center gap-x-2">
|
||||||
|
<div class="hidden sm:flex sm:flex-col sm:items-end">
|
||||||
|
<p
|
||||||
|
class="inline-flex items-center gap-x-1 text-xs/5 text-gray-400"
|
||||||
|
>
|
||||||
|
{{ formatKilobytes(content.size / 1024) }}B
|
||||||
|
<ServerIcon class="size-3" />
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<CheckIcon
|
||||||
|
v-if="!installDepsDisabled[content.versionId]"
|
||||||
|
class="size-5 flex-none text-green-500"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<MinusIcon
|
||||||
|
v-else
|
||||||
|
class="size-5 flex-none text-gray-500"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="installError" class="mt-1 rounded-md bg-red-600/10 p-4">
|
<div v-if="installError" class="mt-1 rounded-md bg-red-600/10 p-4">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
@@ -392,6 +407,48 @@
|
|||||||
</template>
|
</template>
|
||||||
</ModalTemplate>
|
</ModalTemplate>
|
||||||
|
|
||||||
|
<ModalTemplate :model-value="launchOptionsOpen">
|
||||||
|
<template #default>
|
||||||
|
<div class="sm:flex sm:items-start">
|
||||||
|
<div class="mt-3 text-center sm:mt-0 sm:text-left">
|
||||||
|
<h3 class="text-base font-semibold text-zinc-100">
|
||||||
|
Launch {{ game.mName }}
|
||||||
|
</h3>
|
||||||
|
<div class="mt-2">
|
||||||
|
<p class="text-sm text-zinc-400">
|
||||||
|
The instance admin has configured multiple ways to start this
|
||||||
|
game. Select an option to start.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ol class="space-y-2">
|
||||||
|
<li v-for="(launchData, launchIdx) in launchOptions!">
|
||||||
|
<button
|
||||||
|
class="transition w-full rounded-sm bg-zinc-800 inline-flex items-center text-sm py-2 px-3 gap-x-2 text-zinc-100 hover:text-zinc-300 hover:bg-zinc-700"
|
||||||
|
@click="() => launchIndex(launchIdx)"
|
||||||
|
>
|
||||||
|
<PlayIcon class="size-4" />
|
||||||
|
<span>
|
||||||
|
{{ launchData.name }}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</template>
|
||||||
|
<template #buttons>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="mt-3 inline-flex w-full justify-center rounded-md bg-zinc-800 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 hover:bg-zinc-900 sm:mt-0 sm:w-auto"
|
||||||
|
@click="launchOptions = undefined"
|
||||||
|
ref="cancelButtonRef"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</ModalTemplate>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Dear future DecDuck,
|
Dear future DecDuck,
|
||||||
This v-if is necessary for Vue rendering reasons
|
This v-if is necessary for Vue rendering reasons
|
||||||
@@ -470,6 +527,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
||||||
|
<DependencyRequiredModal
|
||||||
|
v-if="dependencyRequiredModal"
|
||||||
|
v-model="dependencyRequiredModal"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -489,9 +551,10 @@ import {
|
|||||||
XMarkIcon,
|
XMarkIcon,
|
||||||
ArrowsPointingOutIcon,
|
ArrowsPointingOutIcon,
|
||||||
PhotoIcon,
|
PhotoIcon,
|
||||||
|
PlayIcon,
|
||||||
} from "@heroicons/vue/20/solid";
|
} from "@heroicons/vue/20/solid";
|
||||||
import { BuildingStorefrontIcon } from "@heroicons/vue/24/outline";
|
import { BuildingStorefrontIcon } from "@heroicons/vue/24/outline";
|
||||||
import { XCircleIcon } from "@heroicons/vue/24/solid";
|
import { MinusIcon, ServerIcon, XCircleIcon } from "@heroicons/vue/24/solid";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { micromark } from "micromark";
|
import { micromark } from "micromark";
|
||||||
import { GameStatusEnum } from "~/types";
|
import { GameStatusEnum } from "~/types";
|
||||||
@@ -520,9 +583,7 @@ const mediaUrls = await Promise.all(
|
|||||||
const htmlDescription = micromark(game.value.mDescription);
|
const htmlDescription = micromark(game.value.mDescription);
|
||||||
|
|
||||||
const installFlowOpen = ref(false);
|
const installFlowOpen = ref(false);
|
||||||
const versionOptions = ref<
|
const versionOptions = ref<undefined | Array<VersionOption>>();
|
||||||
undefined | Array<{ versionName: string; platform: string }>
|
|
||||||
>();
|
|
||||||
const installDirs = ref<undefined | Array<string>>();
|
const installDirs = ref<undefined | Array<string>>();
|
||||||
const currentImageIndex = ref(0);
|
const currentImageIndex = ref(0);
|
||||||
|
|
||||||
@@ -548,15 +609,31 @@ const installLoading = ref(false);
|
|||||||
const installError = ref<string | undefined>();
|
const installError = ref<string | undefined>();
|
||||||
const installVersionIndex = ref(0);
|
const installVersionIndex = ref(0);
|
||||||
const installDir = ref(0);
|
const installDir = ref(0);
|
||||||
|
const installDepsDisabled = ref<{ [key: string]: boolean }>({});
|
||||||
|
|
||||||
|
const currentVersionOption = computed(() => versionOptions.value?.[installVersionIndex.value]);
|
||||||
async function install() {
|
async function install() {
|
||||||
try {
|
try {
|
||||||
if (!versionOptions.value) throw new Error("Versions have not been loaded");
|
if (!versionOptions.value) throw new Error("Versions have not been loaded");
|
||||||
installLoading.value = true;
|
installLoading.value = true;
|
||||||
await invoke("download_game", {
|
const versionOption = versionOptions.value[installVersionIndex.value];
|
||||||
gameId: game.value.id,
|
|
||||||
gameVersion: versionOptions.value[installVersionIndex.value].versionName,
|
const games = [
|
||||||
installDir: installDir.value,
|
{ gameId: game.value.id, versionId: versionOption.versionId },
|
||||||
});
|
...versionOption.requiredContent
|
||||||
|
.filter((v) => !installDepsDisabled.value[v.versionId])
|
||||||
|
.map((v) => ({ gameId: v.gameId, versionId: v.versionId })),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const game of games) {
|
||||||
|
await invoke("download_game", {
|
||||||
|
gameId: game.gameId,
|
||||||
|
versionId: game.versionId,
|
||||||
|
installDir: installDir.value,
|
||||||
|
targetPlatform: versionOption.platform,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
installFlowOpen.value = false;
|
installFlowOpen.value = false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
installError.value = (error as string).toString();
|
installError.value = (error as string).toString();
|
||||||
@@ -573,9 +650,24 @@ async function resumeDownload() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const launchOptions = ref<Array<{ name: string }> | undefined>(undefined);
|
||||||
|
const launchOptionsOpen = computed(() => launchOptions.value !== undefined);
|
||||||
|
|
||||||
async function launch() {
|
async function launch() {
|
||||||
|
if (status.value.type == GameStatusEnum.SetupRequired) {
|
||||||
|
await launchIndex(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await invoke("launch_game", { id: game.value.id });
|
const fetchedLaunchOptions = await invoke<Array<{ name: string }>>(
|
||||||
|
"get_launch_options",
|
||||||
|
{ id: game.value.id }
|
||||||
|
);
|
||||||
|
if (fetchedLaunchOptions.length == 1) {
|
||||||
|
await launchIndex(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
launchOptions.value = fetchedLaunchOptions;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
createModal(
|
createModal(
|
||||||
ModalType.Notification,
|
ModalType.Notification,
|
||||||
@@ -590,6 +682,36 @@ async function launch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dependencyRequiredModal = ref<
|
||||||
|
{ gameId: string; versionId: string } | undefined
|
||||||
|
>(undefined);
|
||||||
|
|
||||||
|
async function launchIndex(index: number) {
|
||||||
|
launchOptions.value = undefined;
|
||||||
|
try {
|
||||||
|
const result = await invoke<LaunchResult>("launch_game", {
|
||||||
|
id: game.value.id,
|
||||||
|
index,
|
||||||
|
});
|
||||||
|
if (result.result == "InstallRequired") {
|
||||||
|
dependencyRequiredModal.value = {
|
||||||
|
gameId: result.data[0],
|
||||||
|
versionId: result.data[1],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
createModal(
|
||||||
|
ModalType.Notification,
|
||||||
|
{
|
||||||
|
title: `Couldn't run "${game.value.mName}"`,
|
||||||
|
description: `Drop failed to launch "${game.value.mName}": ${e}`,
|
||||||
|
buttonText: "Close",
|
||||||
|
},
|
||||||
|
(e, c) => c()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function queue() {
|
async function queue() {
|
||||||
router.push("/queue");
|
router.push("/queue");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
class="bg-zinc-900 z-10 w-32 flex flex-col gap-x-2 font-display items-left justify-center pl-2"
|
class="bg-zinc-900 z-10 w-32 flex flex-col gap-x-2 font-display items-left justify-center pl-2"
|
||||||
>
|
>
|
||||||
<span class="font-bold text-zinc-100">{{ formatKilobytes(stats.speed) }}B/s</span>
|
<span class="font-bold text-zinc-100">{{ formatKilobytes(stats.speed) }}B/s</span>
|
||||||
<span v-if="stats.time > 0" class="text-xs text-zinc-400"
|
<span class="text-xs text-zinc-400"
|
||||||
>{{ formatTime(stats.time) }} left</span
|
>{{ formatTime(stats.time) }} left</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@@ -184,21 +184,10 @@ async function cancelGame(meta: DownloadableMetadata) {
|
|||||||
await invoke("cancel_game", { meta });
|
await invoke("cancel_game", { meta });
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatKilobytes(bytes: number): string {
|
|
||||||
const units = ["K", "M", "G", "T", "P"];
|
|
||||||
let value = bytes;
|
|
||||||
let unitIndex = 0;
|
|
||||||
const scalar = 1000;
|
|
||||||
|
|
||||||
while (value >= scalar && unitIndex < units.length - 1) {
|
|
||||||
value /= scalar;
|
|
||||||
unitIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${value.toFixed(1)} ${units[unitIndex]}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTime(seconds: number): string {
|
function formatTime(seconds: number): string {
|
||||||
|
if (seconds == 0) {
|
||||||
|
return `0s`;
|
||||||
|
}
|
||||||
if (seconds < 60) {
|
if (seconds < 60) {
|
||||||
return `${Math.round(seconds)}s`;
|
return `${Math.round(seconds)}s`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ platformInfo.value = currentPlatform;
|
|||||||
async function openDataDir() {
|
async function openDataDir() {
|
||||||
if (!dataDir.value) return;
|
if (!dataDir.value) return;
|
||||||
try {
|
try {
|
||||||
await open(dataDir.value);
|
await invoke("open_fs", { path: dataDir.value });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to open data dir:", error);
|
console.error("Failed to open data dir:", error);
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ async function openLogFile() {
|
|||||||
if (!dataDir.value) return;
|
if (!dataDir.value) return;
|
||||||
try {
|
try {
|
||||||
const logPath = `${dataDir.value}/drop.log`;
|
const logPath = `${dataDir.value}/drop.log`;
|
||||||
await open(logPath);
|
await invoke("open_fs", { path: logPath });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to open log file:", error);
|
console.error("Failed to open log file:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="grow w-full h-full flex items-center justify-center">
|
<iframe :src="convertedStoreUrl" class="grow w-full h-full" />
|
||||||
<div class="flex flex-col items-center">
|
|
||||||
<BuildingStorefrontIcon
|
|
||||||
class="h-12 w-12 text-blue-600"
|
|
||||||
aria-hidden="true"
|
|
||||||
/>
|
|
||||||
<div class="mt-3 text-center sm:mt-5">
|
|
||||||
<h1 class="text-3xl font-semibold font-display leading-6 text-zinc-100">
|
|
||||||
Store not supported in client
|
|
||||||
</h1>
|
|
||||||
<div class="mt-4">
|
|
||||||
<p class="text-sm text-zinc-400 max-w-lg">
|
|
||||||
Currently, Drop requires you to view the store in your browser.
|
|
||||||
Please click the button below to open it in your default browser.
|
|
||||||
</p>
|
|
||||||
<NuxtLink
|
|
||||||
:href="storeUrl"
|
|
||||||
target="_blank"
|
|
||||||
class="mt-6 transition text-sm/6 font-semibold text-zinc-400 hover:text-zinc-100 inline-flex gap-x-2 items-center duration-200 hover:scale-105"
|
|
||||||
>
|
|
||||||
Open Store <ArrowTopRightOnSquareIcon class="size-4" />
|
|
||||||
</NuxtLink>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import {
|
||||||
ArrowTopRightOnSquareIcon,
|
ArrowTopRightOnSquareIcon,
|
||||||
BuildingStorefrontIcon,
|
BuildingStorefrontIcon,
|
||||||
} from "@heroicons/vue/20/solid";
|
} from "@heroicons/vue/20/solid";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { convertFileSrc, invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
const storeUrl = await invoke<string>("gen_drop_url", { path: "/store" });
|
const convertedStoreUrl = convertFileSrc("store", "server");
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
8217
main/pnpm-lock.yaml
generated
Normal file
8217
main/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
3
main/pnpm-workspace.yaml
Normal file
3
main/pnpm-workspace.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
onlyBuiltDependencies:
|
||||||
|
- '@parcel/watcher'
|
||||||
|
- esbuild
|
||||||
@@ -7,7 +7,6 @@ export default {
|
|||||||
"./plugins/**/*.{js,ts}",
|
"./plugins/**/*.{js,ts}",
|
||||||
"./app.vue",
|
"./app.vue",
|
||||||
"./error.vue",
|
"./error.vue",
|
||||||
"../shared/components/**/*.vue"
|
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {
|
extend: {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export type AppState = {
|
|||||||
|
|
||||||
export type Game = {
|
export type Game = {
|
||||||
id: string;
|
id: string;
|
||||||
|
type: "Game" | "Executor" | "Redist";
|
||||||
mName: string;
|
mName: string;
|
||||||
mShortDescription: string;
|
mShortDescription: string;
|
||||||
mDescription: string;
|
mDescription: string;
|
||||||
@@ -41,6 +42,7 @@ export type Collection = {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
isDefault: boolean;
|
isDefault: boolean;
|
||||||
|
isTools?: boolean;
|
||||||
entries: Array<{ gameId: string; game: Game }>;
|
entries: Array<{ gameId: string; game: Game }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
8091
main/yarn.lock
8091
main/yarn.lock
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
|||||||
WEBKIT_DISABLE_DMABUF_RENDERER=1 yarn tauri dev
|
GSK_RENDERER=ngl pnpm tauri dev
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
|
|
||||||
# build tauri apps
|
# build tauri apps
|
||||||
# NO_STRIP=true yarn tauri build -- --verbose
|
# NO_STRIP=true pnpm tauri build -- --verbose
|
||||||
|
|
||||||
# unpack appimage
|
# unpack appimage
|
||||||
APPIMAGE=$(ls ./src-tauri/target/release/bundle/appimage/*.AppImage)
|
APPIMAGE=$(ls ./src-tauri/target/release/bundle/appimage/*.AppImage)
|
||||||
|
|||||||
@@ -7,17 +7,11 @@
|
|||||||
"tauri": "tauri"
|
"tauri": "tauri"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^2.7.0",
|
|
||||||
"@tauri-apps/plugin-deep-link": "^2.4.1",
|
|
||||||
"@tauri-apps/plugin-dialog": "^2.3.2",
|
|
||||||
"@tauri-apps/plugin-opener": "^2.4.0",
|
|
||||||
"@tauri-apps/plugin-os": "^2.3.0",
|
|
||||||
"@tauri-apps/plugin-shell": "^2.3.0",
|
|
||||||
"pino": "^9.7.0",
|
"pino": "^9.7.0",
|
||||||
"pino-pretty": "^13.1.1",
|
"pino-pretty": "^13.1.1",
|
||||||
"tauri": "^0.15.0"
|
"tauri": "^0.15.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tauri-apps/cli": "^2.7.1"
|
"@tauri-apps/cli": "^2.9.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5583
pnpm-lock.yaml
generated
Normal file
5583
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
pnpm-workspace.yaml
Normal file
21
pnpm-workspace.yaml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
onlyBuiltDependencies:
|
||||||
|
- sharp
|
||||||
|
|
||||||
|
overrides:
|
||||||
|
cross-spawn@<6.0.6: '>=6.0.6'
|
||||||
|
cross-spawn@>=7.0.0 <7.0.5: '>=7.0.5'
|
||||||
|
form-data@<2.5.4: '>=2.5.4'
|
||||||
|
got@<11.8.5: '>=11.8.5'
|
||||||
|
http-cache-semantics@<4.1.1: '>=4.1.1'
|
||||||
|
lodash@<4.17.21: '>=4.17.21'
|
||||||
|
lodash@>=4.0.0 <4.17.21: '>=4.17.21'
|
||||||
|
minimist@>=1.0.0 <1.2.6: '>=1.2.6'
|
||||||
|
nth-check@<2.0.1: '>=2.0.1'
|
||||||
|
semver-regex@<3.1.3: '>=3.1.3'
|
||||||
|
semver-regex@<3.1.4: '>=3.1.4'
|
||||||
|
semver@>=7.0.0 <7.5.2: '>=7.5.2'
|
||||||
|
sharp@<0.30.5: '>=0.30.5'
|
||||||
|
sharp@<0.32.6: '>=0.32.6'
|
||||||
|
tmp@<=0.2.3: '>=0.2.4'
|
||||||
|
tough-cookie@<4.1.3: '>=4.1.3'
|
||||||
|
trim-newlines@<3.0.1: '>=3.0.1'
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
<template>
|
|
||||||
<NuxtLoadingIndicator color="#2563eb" />
|
|
||||||
<NuxtLayout class="select-none w-screen h-screen">
|
|
||||||
<NuxtPage />
|
|
||||||
<ModalStack />
|
|
||||||
</NuxtLayout>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import "~/composables/downloads.js";
|
|
||||||
|
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import { useAppState } from "./composables/app-state.js";
|
|
||||||
import {
|
|
||||||
initialNavigation,
|
|
||||||
setupHooks,
|
|
||||||
} from "./composables/state-navigation.js";
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const state = useAppState();
|
|
||||||
|
|
||||||
async function fetchState() {
|
|
||||||
try {
|
|
||||||
state.value = JSON.parse(await invoke("fetch_state"));
|
|
||||||
if (!state.value)
|
|
||||||
throw createError({
|
|
||||||
statusCode: 500,
|
|
||||||
statusMessage: `App state is: ${state.value}`,
|
|
||||||
fatal: true,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error("failed to parse state", e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await fetchState();
|
|
||||||
|
|
||||||
// This is inefficient but apparently we do it lol
|
|
||||||
router.beforeEach(async () => {
|
|
||||||
await fetchState();
|
|
||||||
});
|
|
||||||
|
|
||||||
setupHooks();
|
|
||||||
initialNavigation(state);
|
|
||||||
|
|
||||||
useHead({
|
|
||||||
title: "Drop",
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
@tailwind base;
|
|
||||||
@tailwind components;
|
|
||||||
@tailwind utilities;
|
|
||||||
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
-ms-overflow-style: none; /* IE and Edge /
|
|
||||||
scrollbar-width: none; / Firefox */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Hide scrollbar for Chrome, Safari and Opera */
|
|
||||||
html::-webkit-scrollbar {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
$motiva: (
|
|
||||||
("MotivaSansThin.ttf", "ttf", 100, normal),
|
|
||||||
("MotivaSansLight.woff.ttf", "woff", 300, normal),
|
|
||||||
("MotivaSansRegular.woff.ttf", "woff", 400, normal),
|
|
||||||
("MotivaSansMedium.woff.ttf", "woff", 500, normal),
|
|
||||||
("MotivaSansBold.woff.ttf", "woff", 600, normal),
|
|
||||||
("MotivaSansExtraBold.ttf", "woff", 700, normal),
|
|
||||||
("MotivaSansBlack.woff.ttf", "woff", 900, normal)
|
|
||||||
);
|
|
||||||
|
|
||||||
$helvetica: (
|
|
||||||
("Helvetica.woff", "woff", 400, normal),
|
|
||||||
("Helvetica-Oblique.woff", "woff", 400, italic),
|
|
||||||
("Helvetica-Bold.woff", "woff", 600, normal),
|
|
||||||
("Helvetica-BoldOblique.woff", "woff", 600, italic),
|
|
||||||
("helvetica-light-587ebe5a59211.woff2", "woff2", 300, normal)
|
|
||||||
);
|
|
||||||
|
|
||||||
@each $file, $format, $weight, $style in $motiva {
|
|
||||||
@font-face {
|
|
||||||
font-family: "Motiva Sans";
|
|
||||||
src: url("/fonts/motiva/#{$file}") format($format);
|
|
||||||
font-weight: $weight;
|
|
||||||
font-style: $style;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@each $file, $format, $weight, $style in $helvetica {
|
|
||||||
@font-face {
|
|
||||||
font-family: "Helvetica";
|
|
||||||
src: url("/fonts/helvetica/#{$file}") format($format);
|
|
||||||
font-weight: $weight;
|
|
||||||
font-style: $style;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@font-face {
|
|
||||||
font-family: "Inter";
|
|
||||||
src: url("/fonts/inter/InterVariable.ttf");
|
|
||||||
font-style: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@font-face {
|
|
||||||
font-family: "Inter";
|
|
||||||
src: url("/fonts/inter/InterVariable-Italic.ttf");
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ===== Scrollbar CSS ===== */
|
|
||||||
/* Firefox */
|
|
||||||
* {
|
|
||||||
scrollbar-width: 4px;
|
|
||||||
scrollbar-color: #52525b #00000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Chrome, Edge, and Safari */
|
|
||||||
*::-webkit-scrollbar {
|
|
||||||
width: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
*::-webkit-scrollbar-track {
|
|
||||||
background: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
*::-webkit-scrollbar-thumb {
|
|
||||||
background-color: #52525b;
|
|
||||||
border-radius: 10px;
|
|
||||||
border: 3px solid #52525b;
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
<template>
|
|
||||||
<NuxtLayout name="default">
|
|
||||||
<div
|
|
||||||
class="grid min-h-full grid-cols-1 grid-rows-[1fr,auto,1fr] lg:grid-cols-[max(50%,36rem),1fr]"
|
|
||||||
>
|
|
||||||
<header
|
|
||||||
class="mx-auto w-full max-w-7xl px-6 pt-6 sm:pt-10 lg:col-span-2 lg:col-start-1 lg:row-start-1 lg:px-8"
|
|
||||||
>
|
|
||||||
<Logo class="h-10 w-auto sm:h-12" />
|
|
||||||
|
|
||||||
</header>
|
|
||||||
<main
|
|
||||||
class="mx-auto w-full max-w-7xl px-6 py-24 sm:py-32 lg:col-span-2 lg:col-start-1 lg:row-start-2 lg:px-8"
|
|
||||||
>
|
|
||||||
<div class="max-w-lg">
|
|
||||||
<p class="text-base font-semibold leading-8 text-blue-600">
|
|
||||||
{{ error?.statusCode }}
|
|
||||||
</p>
|
|
||||||
<h1
|
|
||||||
class="mt-4 text-3xl font-bold font-display tracking-tight text-zinc-100 sm:text-5xl"
|
|
||||||
>
|
|
||||||
Oh no!
|
|
||||||
</h1>
|
|
||||||
<p
|
|
||||||
v-if="message"
|
|
||||||
class="mt-3 font-bold text-base leading-7 text-red-500"
|
|
||||||
>
|
|
||||||
{{ message }}
|
|
||||||
</p>
|
|
||||||
<p class="mt-6 text-base leading-7 text-zinc-400">
|
|
||||||
An error occurred while responding to your request. If you believe
|
|
||||||
this to be a bug, please report it. Try signing in and see if it
|
|
||||||
resolves the issue.
|
|
||||||
</p>
|
|
||||||
<div class="mt-10">
|
|
||||||
<!-- full app reload to fix errors -->
|
|
||||||
<a
|
|
||||||
href="/store"
|
|
||||||
class="text-sm font-semibold leading-7 text-blue-600"
|
|
||||||
><span aria-hidden="true">←</span> Back to store</a
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
<footer class="self-end lg:col-span-2 lg:col-start-1 lg:row-start-3">
|
|
||||||
<div class="border-t border-zinc-700 bg-zinc-900 py-10">
|
|
||||||
<nav
|
|
||||||
class="mx-auto flex w-full max-w-7xl items-center gap-x-4 px-6 text-sm leading-7 text-zinc-400 lg:px-8"
|
|
||||||
>
|
|
||||||
<NuxtLink href="/docs">Documentation</NuxtLink>
|
|
||||||
<svg
|
|
||||||
viewBox="0 0 2 2"
|
|
||||||
aria-hidden="true"
|
|
||||||
class="h-0.5 w-0.5 fill-zinc-600"
|
|
||||||
>
|
|
||||||
<circle cx="1" cy="1" r="1" />
|
|
||||||
</svg>
|
|
||||||
<a href="https://discord.gg/NHx46XKJWA" target="_blank"
|
|
||||||
>Support Discord</a
|
|
||||||
>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
<div
|
|
||||||
class="hidden lg:relative lg:col-start-2 lg:row-start-1 lg:row-end-4 lg:block"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="@/assets/wallpaper.jpg"
|
|
||||||
alt=""
|
|
||||||
class="absolute inset-0 h-full w-full object-cover"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</NuxtLayout>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import type { NuxtError } from "#app";
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
error: Object as () => NuxtError,
|
|
||||||
});
|
|
||||||
|
|
||||||
const statusCode = props.error?.statusCode;
|
|
||||||
const message =
|
|
||||||
props.error?.statusMessage ||
|
|
||||||
props.error?.message ||
|
|
||||||
"An unknown error occurred.";
|
|
||||||
|
|
||||||
console.error(props.error);
|
|
||||||
</script>
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
||||||
export default defineNuxtConfig({
|
|
||||||
compatibilityDate: "2024-04-03",
|
|
||||||
|
|
||||||
postcss: {
|
|
||||||
plugins: {
|
|
||||||
tailwindcss: {},
|
|
||||||
autoprefixer: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
css: ["~/assets/main.scss"],
|
|
||||||
|
|
||||||
ssr: false,
|
|
||||||
|
|
||||||
extends: [["../libs/drop-base"]],
|
|
||||||
|
|
||||||
app: {
|
|
||||||
baseURL: "/main",
|
|
||||||
},
|
|
||||||
|
|
||||||
devtools: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "view",
|
|
||||||
"private": true,
|
|
||||||
"version": "0.3.3",
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"build": "nuxt generate",
|
|
||||||
"dev": "nuxt dev",
|
|
||||||
"postinstall": "nuxt prepare",
|
|
||||||
"tauri": "tauri"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@headlessui/vue": "^1.7.23",
|
|
||||||
"@heroicons/vue": "^2.1.5",
|
|
||||||
"@nuxtjs/tailwindcss": "^6.12.2",
|
|
||||||
"@tauri-apps/api": "^2.7.0",
|
|
||||||
"koa": "^2.16.1",
|
|
||||||
"markdown-it": "^14.1.0",
|
|
||||||
"micromark": "^4.0.1",
|
|
||||||
"nuxt": "^3.16.0",
|
|
||||||
"scss": "^0.2.4",
|
|
||||||
"vue-router": "latest",
|
|
||||||
"vuedraggable": "^4.1.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@tailwindcss/forms": "^0.5.9",
|
|
||||||
"@tailwindcss/typography": "^0.5.15",
|
|
||||||
"@types/markdown-it": "^14.1.2",
|
|
||||||
"autoprefixer": "^10.4.20",
|
|
||||||
"postcss": "^8.4.47",
|
|
||||||
"sass-embedded": "^1.79.4",
|
|
||||||
"tailwindcss": "^3.4.13",
|
|
||||||
"typescript": "^5.8.3",
|
|
||||||
"vue-tsc": "^2.2.10"
|
|
||||||
},
|
|
||||||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/** @type {import('tailwindcss').Config} */
|
|
||||||
export default {
|
|
||||||
content: [
|
|
||||||
"./components/**/*.{js,vue,ts}",
|
|
||||||
"./layouts/**/*.vue",
|
|
||||||
"./pages/**/*.vue",
|
|
||||||
"./plugins/**/*.{js,ts}",
|
|
||||||
"./app.vue",
|
|
||||||
"./error.vue",
|
|
||||||
],
|
|
||||||
theme: {
|
|
||||||
extend: {
|
|
||||||
fontFamily: {
|
|
||||||
sans: ["Inter"],
|
|
||||||
display: ["Motiva Sans"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
plugins: [require("@tailwindcss/forms"), require('@tailwindcss/typography')],
|
|
||||||
};
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
// https://nuxt.com/docs/guide/concepts/typescript
|
|
||||||
"extends": "./.nuxt/tsconfig.json",
|
|
||||||
"exclude": ["src-tauri/**/*"]
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
import type { Component } from "vue";
|
|
||||||
|
|
||||||
export type NavigationItem = {
|
|
||||||
prefix: string;
|
|
||||||
route: string;
|
|
||||||
label: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type QuickActionNav = {
|
|
||||||
icon: Component;
|
|
||||||
notifications?: number;
|
|
||||||
action: () => Promise<void>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type User = {
|
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
admin: boolean;
|
|
||||||
displayName: string;
|
|
||||||
profilePictureObjectId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type AppState = {
|
|
||||||
status: AppStatus;
|
|
||||||
user?: User;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Game = {
|
|
||||||
id: string;
|
|
||||||
mName: string;
|
|
||||||
mShortDescription: string;
|
|
||||||
mDescription: string;
|
|
||||||
mIconObjectId: string;
|
|
||||||
mBannerObjectId: string;
|
|
||||||
mCoverObjectId: string;
|
|
||||||
mImageLibraryObjectIds: string[];
|
|
||||||
mImageCarouselObjectIds: string[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Collection = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
isDefault: boolean;
|
|
||||||
entries: Array<{ gameId: string; game: Game }>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type GameVersion = {
|
|
||||||
launchCommandTemplate: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export enum AppStatus {
|
|
||||||
NotConfigured = "NotConfigured",
|
|
||||||
Offline = "Offline",
|
|
||||||
SignedOut = "SignedOut",
|
|
||||||
SignedIn = "SignedIn",
|
|
||||||
SignedInNeedsReauth = "SignedInNeedsReauth",
|
|
||||||
ServerUnavailable = "ServerUnavailable",
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum GameStatusEnum {
|
|
||||||
Remote = "Remote",
|
|
||||||
Queued = "Queued",
|
|
||||||
Downloading = "Downloading",
|
|
||||||
Validating = "Validating",
|
|
||||||
Installed = "Installed",
|
|
||||||
Updating = "Updating",
|
|
||||||
Uninstalling = "Uninstalling",
|
|
||||||
SetupRequired = "SetupRequired",
|
|
||||||
Running = "Running",
|
|
||||||
PartiallyInstalled = "PartiallyInstalled",
|
|
||||||
}
|
|
||||||
|
|
||||||
export type GameStatus = {
|
|
||||||
type: GameStatusEnum;
|
|
||||||
version_name?: string;
|
|
||||||
install_dir?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export enum DownloadableType {
|
|
||||||
Game = "Game",
|
|
||||||
Tool = "Tool",
|
|
||||||
DLC = "DLC",
|
|
||||||
Mod = "Mod",
|
|
||||||
}
|
|
||||||
|
|
||||||
export type DownloadableMetadata = {
|
|
||||||
id: string;
|
|
||||||
version: string;
|
|
||||||
downloadType: DownloadableType;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Settings = {
|
|
||||||
autostart: boolean;
|
|
||||||
maxDownloadThreads: number;
|
|
||||||
forceOffline: boolean;
|
|
||||||
};
|
|
||||||
8091
shared/yarn.lock
8091
shared/yarn.lock
File diff suppressed because it is too large
Load Diff
1979
src-tauri/Cargo.lock
generated
1979
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,154 +1,150 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "drop-app"
|
name = "drop-app"
|
||||||
version = "0.3.3"
|
version = "0.4.0"
|
||||||
description = "The client application for the open-source, self-hosted game distribution platform Drop"
|
description = "The client application for the open-source, self-hosted game distribution platform Drop"
|
||||||
authors = ["Drop OSS"]
|
authors = ["Drop OSS"]
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[workspace]
|
||||||
|
resolver = "3"
|
||||||
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies]
|
members = [
|
||||||
tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }
|
"client",
|
||||||
|
"cloud_saves",
|
||||||
|
"database",
|
||||||
|
"download_manager",
|
||||||
|
"games",
|
||||||
|
"process",
|
||||||
|
"remote",
|
||||||
|
"utils",
|
||||||
|
]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
crate-type = ["cdylib", "rlib", "staticlib"]
|
||||||
# The `_lib` suffix may seem redundant but it is necessary
|
# The `_lib` suffix may seem redundant but it is necessary
|
||||||
# to make the lib name unique and wouldn't conflict with the bin name.
|
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||||
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
||||||
name = "drop_app_lib"
|
name = "drop_app_lib"
|
||||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
|
||||||
rustflags = ["-C", "target-feature=+aes,+sse2"]
|
rustflags = ["-C", "target-feature=+aes,+sse2"]
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
[build-dependencies]
|
|
||||||
tauri-build = { version = "2.0.0", features = [] }
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tauri-plugin-shell = "2.2.1"
|
|
||||||
serde_json = "1"
|
|
||||||
rayon = "1.10.0"
|
|
||||||
webbrowser = "1.0.2"
|
|
||||||
url = "2.5.2"
|
|
||||||
tauri-plugin-deep-link = "2"
|
|
||||||
log = "0.4.22"
|
|
||||||
hex = "0.4.3"
|
|
||||||
tauri-plugin-dialog = "2"
|
|
||||||
http = "1.1.0"
|
|
||||||
urlencoding = "2.1.3"
|
|
||||||
md5 = "0.7.0"
|
|
||||||
chrono = "0.4.38"
|
|
||||||
tauri-plugin-os = "2"
|
|
||||||
boxcar = "0.2.7"
|
|
||||||
umu-wrapper-lib = "0.1.0"
|
|
||||||
tauri-plugin-autostart = "2.0.0"
|
|
||||||
shared_child = "1.0.1"
|
|
||||||
serde_with = "3.12.0"
|
|
||||||
slice-deque = "0.3.0"
|
|
||||||
throttle_my_fn = "0.2.6"
|
|
||||||
parking_lot = "0.12.3"
|
|
||||||
atomic-instant-full = "0.1.0"
|
atomic-instant-full = "0.1.0"
|
||||||
|
bitcode = "0.6.6"
|
||||||
|
boxcar = "0.2.7"
|
||||||
|
bytes = "1.10.1"
|
||||||
cacache = "13.1.0"
|
cacache = "13.1.0"
|
||||||
|
chrono = "0.4.38"
|
||||||
|
client = { path = "./client", version = "0.1.0" } # client
|
||||||
|
database = { path = "./database" } # database
|
||||||
|
deranged = "=0.4.0"
|
||||||
|
dirs = "6.0.0"
|
||||||
|
download_manager = { path = "./download_manager", version = "0.1.0" } # download manager
|
||||||
|
droplet-rs = "0.7.3"
|
||||||
|
filetime = "0.2.25"
|
||||||
|
futures-core = "0.3.31"
|
||||||
|
futures-lite = "2.6.0"
|
||||||
|
games = { path = "./games", version = "0.1.0" } # games
|
||||||
|
gethostname = "1.0.1"
|
||||||
|
hex = "0.4.3"
|
||||||
|
http = "1.1.0"
|
||||||
http-serde = "2.1.1"
|
http-serde = "2.1.1"
|
||||||
|
humansize = "2.1.3"
|
||||||
|
known-folders = "1.2.0"
|
||||||
|
log = "0.4.22"
|
||||||
|
md5 = "0.7.0"
|
||||||
|
native_model = { git = "https://github.com/Drop-OSS/native_model.git", version = "0.6.4", features = [
|
||||||
|
"rmp_serde_1_3",
|
||||||
|
] }
|
||||||
|
page_size = "0.6.0"
|
||||||
|
parking_lot = "0.12.3"
|
||||||
|
process = { path = "./process" } # process
|
||||||
|
rand = "0.9.1"
|
||||||
|
rayon = "1.10.0"
|
||||||
|
regex = "1.11.1"
|
||||||
|
remote = { path = "./remote", version = "0.1.0" } # remote
|
||||||
|
reqwest = { version = "0.12.28", default-features = false, features = [
|
||||||
|
"blocking",
|
||||||
|
"http2",
|
||||||
|
"json",
|
||||||
|
"native-tls-alpn",
|
||||||
|
"rustls-tls",
|
||||||
|
"rustls-tls-native-roots",
|
||||||
|
"stream",
|
||||||
|
] }
|
||||||
reqwest-middleware = "0.4.0"
|
reqwest-middleware = "0.4.0"
|
||||||
reqwest-middleware-cache = "0.1.1"
|
reqwest-middleware-cache = "0.1.1"
|
||||||
deranged = "=0.4.0"
|
|
||||||
droplet-rs = "0.7.3"
|
|
||||||
gethostname = "1.0.1"
|
|
||||||
zstd = "0.13.3"
|
|
||||||
tar = "0.4.44"
|
|
||||||
rand = "0.9.1"
|
|
||||||
regex = "1.11.1"
|
|
||||||
tempfile = "3.19.1"
|
|
||||||
schemars = "0.8.22"
|
|
||||||
sha1 = "0.10.6"
|
|
||||||
dirs = "6.0.0"
|
|
||||||
whoami = "1.6.0"
|
|
||||||
filetime = "0.2.25"
|
|
||||||
walkdir = "2.5.0"
|
|
||||||
known-folders = "1.2.0"
|
|
||||||
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
|
|
||||||
tauri-plugin-opener = "2.4.0"
|
|
||||||
bitcode = "0.6.6"
|
|
||||||
reqwest-websocket = "0.5.0"
|
reqwest-websocket = "0.5.0"
|
||||||
futures-lite = "2.6.0"
|
schemars = "0.8.22"
|
||||||
page_size = "0.6.0"
|
serde_json = "1"
|
||||||
|
serde_with = "3.12.0"
|
||||||
|
sha1 = "0.10.6"
|
||||||
|
shared_child = "1.0.1"
|
||||||
|
slice-deque = "0.3.0"
|
||||||
sysinfo = "0.36.1"
|
sysinfo = "0.36.1"
|
||||||
humansize = "2.1.3"
|
tar = "0.4.44"
|
||||||
|
tauri-plugin-autostart = "*"
|
||||||
|
tauri-plugin-deep-link = "*"
|
||||||
|
tauri-plugin-dialog = "*"
|
||||||
|
tauri-plugin-opener = "*"
|
||||||
|
tauri-plugin-os = "*"
|
||||||
|
tauri-plugin-shell = "*"
|
||||||
|
tempfile = "3.19.1"
|
||||||
|
throttle_my_fn = "0.2.6"
|
||||||
tokio-util = { version = "0.7.16", features = ["io"] }
|
tokio-util = { version = "0.7.16", features = ["io"] }
|
||||||
futures-core = "0.3.31"
|
umu-wrapper-lib = "0.1.0"
|
||||||
bytes = "1.10.1"
|
url = "2.5.2"
|
||||||
# tailscale = { path = "./tailscale" }
|
urlencoding = "2.1.3"
|
||||||
|
utils = { path = "./utils" } # utils
|
||||||
|
walkdir = "2.5.0"
|
||||||
# Workspaces
|
webbrowser = "1.0.2"
|
||||||
client = { version = "0.1.0", path = "./client" }
|
whoami = "1.6.0"
|
||||||
database = { path = "./database" }
|
wry = { version = "*", features = [] }
|
||||||
process = { path = "./process" }
|
zstd = "0.13.3"
|
||||||
remote = { version = "0.1.0", path = "./remote" }
|
|
||||||
utils = { path = "./utils" }
|
|
||||||
games = { version = "0.1.0", path = "./games" }
|
|
||||||
download_manager = { version = "0.1.0", path = "./download_manager" }
|
|
||||||
|
|
||||||
[dependencies.dynfmt]
|
|
||||||
version = "0.1.5"
|
|
||||||
features = ["curly"]
|
|
||||||
|
|
||||||
[dependencies.tauri]
|
|
||||||
version = "2.7.0"
|
|
||||||
features = ["protocol-asset", "tray-icon"]
|
|
||||||
|
|
||||||
[dependencies.tokio]
|
|
||||||
version = "1.40.0"
|
|
||||||
features = ["rt", "tokio-macros", "signal"]
|
|
||||||
|
|
||||||
[dependencies.log4rs]
|
[dependencies.log4rs]
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
features = ["console_appender", "file_appender"]
|
features = ["console_appender", "file_appender"]
|
||||||
|
|
||||||
|
[dependencies.rustbreak]
|
||||||
|
version = "2"
|
||||||
|
features = ["other_errors"] # You can also use "yaml_enc" or "bin_enc"
|
||||||
|
|
||||||
[dependencies.rustix]
|
[dependencies.rustix]
|
||||||
version = "0.38.37"
|
version = "0.38.37"
|
||||||
features = ["fs"]
|
features = ["fs"]
|
||||||
|
|
||||||
[dependencies.uuid]
|
|
||||||
version = "1.10.0"
|
|
||||||
features = ["v4", "fast-rng", "macro-diagnostics"]
|
|
||||||
|
|
||||||
[dependencies.rustbreak]
|
|
||||||
version = "2"
|
|
||||||
features = ["other_errors"] # You can also use "yaml_enc" or "bin_enc"
|
|
||||||
|
|
||||||
[dependencies.reqwest]
|
|
||||||
version = "0.12.22"
|
|
||||||
default-features = false
|
|
||||||
features = [
|
|
||||||
"json",
|
|
||||||
"http2",
|
|
||||||
"blocking",
|
|
||||||
"rustls-tls",
|
|
||||||
"native-tls-alpn",
|
|
||||||
"rustls-tls-native-roots",
|
|
||||||
"stream",
|
|
||||||
]
|
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
version = "1"
|
version = "1"
|
||||||
features = ["derive", "rc"]
|
features = ["derive", "rc"]
|
||||||
|
|
||||||
|
[dependencies.tauri]
|
||||||
|
version = "2.9.5"
|
||||||
|
features = ["protocol-asset", "tray-icon", "unstable"]
|
||||||
|
|
||||||
|
[dependencies.tokio]
|
||||||
|
version = "1.40.0"
|
||||||
|
features = ["rt", "signal", "tokio-macros"]
|
||||||
|
|
||||||
|
[dependencies.uuid]
|
||||||
|
version = "1.10.0"
|
||||||
|
features = ["fast-rng", "macro-diagnostics", "v4"]
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tauri-build = { version = "*", features = [] }
|
||||||
|
|
||||||
|
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies]
|
||||||
|
tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
panic = "abort"
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
panic = 'abort'
|
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
# Set the default for dependencies in Development mode.
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
[workspace]
|
[profile.dev]
|
||||||
members = [
|
# Turn on a small amount of optimisation in Development mode.
|
||||||
"client",
|
opt-level = 1
|
||||||
"database",
|
|
||||||
"process",
|
|
||||||
"remote",
|
|
||||||
"utils",
|
|
||||||
"cloud_saves",
|
|
||||||
"download_manager",
|
|
||||||
"games",
|
|
||||||
]
|
|
||||||
|
|
||||||
resolver = "3"
|
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitcode = "0.6.7"
|
bitcode = "*"
|
||||||
database = { version = "0.1.0", path = "../database" }
|
database = { version = "*", path = "../database" }
|
||||||
log = "0.4.28"
|
log = "*"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "*", features = ["derive"] }
|
||||||
tauri = "2.8.5"
|
tauri = "*"
|
||||||
tauri-plugin-autostart = "2.5.0"
|
tauri-plugin-autostart = "*"
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::{app_status::AppStatus, user::User};
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct AppState {
|
||||||
|
pub status: AppStatus,
|
||||||
|
pub user: Option<User>
|
||||||
|
}
|
||||||
@@ -2,3 +2,4 @@ pub mod app_status;
|
|||||||
pub mod autostart;
|
pub mod autostart;
|
||||||
pub mod compat;
|
pub mod compat;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
pub mod app_state;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ impl BackupManager<'_> {
|
|||||||
current_platform: Platform::Windows,
|
current_platform: Platform::Windows,
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
current_platform: Platform::MacOs,
|
current_platform: Platform::macOS,
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
current_platform: Platform::Linux,
|
current_platform: Platform::Linux,
|
||||||
@@ -43,7 +43,7 @@ impl BackupManager<'_> {
|
|||||||
&LinuxBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
&LinuxBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
(Platform::MacOs, Platform::MacOs),
|
(Platform::macOS, Platform::macOS),
|
||||||
&MacBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
&MacBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
|
|||||||
@@ -4,11 +4,15 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
aes = "0.8.4"
|
||||||
|
anyhow = "*"
|
||||||
chrono = "0.4.42"
|
chrono = "0.4.42"
|
||||||
|
ctr = "0.9.2"
|
||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
|
keyring = { version = "3.6.3", features = ["apple-native", "crypto-rust", "linux-native-sync-persistent", "windows-native"] }
|
||||||
log = "0.4.28"
|
log = "0.4.28"
|
||||||
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
|
rand = "0.9.2"
|
||||||
rustbreak = "2.0.0"
|
ron = "0.12.0"
|
||||||
serde = "1.0.228"
|
serde = "1.0.228"
|
||||||
serde_with = "3.15.0"
|
serde_with = "3.15.0"
|
||||||
url = "2.5.7"
|
url = "2.5.7"
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ use std::{
|
|||||||
sync::{Arc, LazyLock},
|
sync::{Arc, LazyLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use rustbreak::{DeSerError, DeSerializer};
|
use keyring::Entry;
|
||||||
use serde::{Serialize, de::DeserializeOwned};
|
use log::info;
|
||||||
|
|
||||||
use crate::interface::{DatabaseImpls, DatabaseInterface};
|
use crate::interface::{DatabaseInterface};
|
||||||
|
|
||||||
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(DatabaseInterface::set_up_database);
|
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(DatabaseInterface::set_up_database);
|
||||||
|
|
||||||
@@ -23,23 +23,15 @@ pub static DATA_ROOT_DIR: LazyLock<Arc<PathBuf>> = LazyLock::new(|| {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Custom JSON serializer to support everything we need
|
pub(crate) static KEY_IV: LazyLock<([u8; 16], [u8; 16])> = LazyLock::new(|| {
|
||||||
#[derive(Debug, Default, Clone)]
|
let entry = Entry::new("drop", "database_key").expect("failed to open keyring");
|
||||||
pub struct DropDatabaseSerializer;
|
let mut key = entry.get_secret().unwrap_or_else(|_| {
|
||||||
|
let mut buffer = [0u8; 32];
|
||||||
impl<T: native_model::Model + Serialize + DeserializeOwned> DeSerializer<T>
|
rand::fill(&mut buffer);
|
||||||
for DropDatabaseSerializer
|
entry.set_secret(&buffer).expect("failed to save key");
|
||||||
{
|
info!("created new database key");
|
||||||
fn serialize(&self, val: &T) -> rustbreak::error::DeSerResult<Vec<u8>> {
|
buffer.to_vec()
|
||||||
native_model::encode(val).map_err(|e| DeSerError::Internal(e.to_string()))
|
});
|
||||||
}
|
let new = key.split_off(16);
|
||||||
|
(new.try_into().expect("failed to extract key"), key.try_into().expect("failed to extract iv"))
|
||||||
fn deserialize<R: std::io::Read>(&self, mut s: R) -> rustbreak::error::DeSerResult<T> {
|
});
|
||||||
let mut buf = Vec::new();
|
|
||||||
s.read_to_end(&mut buf)
|
|
||||||
.map_err(|e| rustbreak::error::DeSerError::Other(e.into()))?;
|
|
||||||
let (val, _version) =
|
|
||||||
native_model::decode(buf).map_err(|e| DeSerError::Internal(e.to_string()))?;
|
|
||||||
Ok(val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,30 +2,32 @@ use std::{
|
|||||||
fs::{self, create_dir_all},
|
fs::{self, create_dir_all},
|
||||||
mem::ManuallyDrop,
|
mem::ManuallyDrop,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
sync::{RwLockReadGuard, RwLockWriteGuard},
|
sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use aes::cipher::{KeyIvInit as _, StreamCipher as _};
|
||||||
|
use anyhow::Error;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use rustbreak::{PathDatabase, RustbreakError};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::{DATA_ROOT_DIR, DB, DropDatabaseSerializer},
|
db::{DATA_ROOT_DIR, DB, KEY_IV},
|
||||||
models::data::Database,
|
models::{
|
||||||
|
self,
|
||||||
|
data::{Database, DatabaseVersionSerializable},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type DatabaseInterface =
|
type Aes128Ctr64LE = ctr::Ctr64LE<aes::Aes128>;
|
||||||
rustbreak::Database<Database, rustbreak::backend::PathBackend, DropDatabaseSerializer>;
|
|
||||||
|
|
||||||
pub trait DatabaseImpls {
|
pub struct DatabaseInterface {
|
||||||
fn set_up_database() -> DatabaseInterface;
|
data: RwLock<models::data::Database>,
|
||||||
fn database_is_set_up(&self) -> bool;
|
path: PathBuf,
|
||||||
fn fetch_base_url(&self) -> Url;
|
|
||||||
}
|
}
|
||||||
impl DatabaseImpls for DatabaseInterface {
|
impl DatabaseInterface {
|
||||||
fn set_up_database() -> DatabaseInterface {
|
pub fn set_up_database() -> Self {
|
||||||
let db_path = DATA_ROOT_DIR.join("drop.db");
|
let db_path = DATA_ROOT_DIR.join("drop.db");
|
||||||
let games_base_dir = DATA_ROOT_DIR.join("games");
|
let games_base_dir = DATA_ROOT_DIR.join("games");
|
||||||
let logs_root_dir = DATA_ROOT_DIR.join("logs");
|
let logs_root_dir = DATA_ROOT_DIR.join("logs");
|
||||||
@@ -78,36 +80,95 @@ impl DatabaseImpls for DatabaseInterface {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if exists {
|
if exists {
|
||||||
match PathDatabase::load_from_path(db_path.clone()) {
|
match DatabaseInterface::open_at_path(&db_path) {
|
||||||
Ok(db) => db,
|
Ok(db) => db.unwrap(),
|
||||||
Err(e) => handle_invalid_database(e, db_path, games_base_dir, cache_dir),
|
Err(e) => handle_invalid_database(e, db_path, games_base_dir, cache_dir)
|
||||||
|
.expect("failed to recover from failed database"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let default = Database::new(games_base_dir, None, cache_dir);
|
let default = Database::new(games_base_dir, None, cache_dir);
|
||||||
debug!("Creating database at path {}", db_path.display());
|
debug!("Creating database at path {}", db_path.display());
|
||||||
PathDatabase::create_at_path(db_path, default).expect("Database could not be created")
|
DatabaseInterface::create_at_path(&db_path, default)
|
||||||
|
.expect("Database could not be created")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn database_is_set_up(&self) -> bool {
|
pub fn open_at_path(db_path: &Path) -> Result<Option<DatabaseInterface>, Error> {
|
||||||
|
if !db_path.exists() {
|
||||||
|
return Ok(None);
|
||||||
|
};
|
||||||
|
let mut database_data = std::fs::read(db_path)?;
|
||||||
|
let (key, iv) = *KEY_IV;
|
||||||
|
let mut cipher = Aes128Ctr64LE::new(&key.into(), &iv.into());
|
||||||
|
cipher.apply_keystream(&mut database_data);
|
||||||
|
|
||||||
|
let database_data = String::from_utf8(database_data)?;
|
||||||
|
|
||||||
|
let database_data: DatabaseVersionSerializable = ron::from_str(&database_data)?;
|
||||||
|
Ok(Some(DatabaseInterface {
|
||||||
|
data: RwLock::new(database_data.0),
|
||||||
|
path: db_path.to_path_buf(),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_at_path(db_path: &Path, database: Database) -> Result<DatabaseInterface, Error> {
|
||||||
|
let database = DatabaseVersionSerializable(database);
|
||||||
|
let mut database_data = ron::to_string(&database)?.into_bytes();
|
||||||
|
|
||||||
|
let (key, iv) = *KEY_IV;
|
||||||
|
let mut cipher = Aes128Ctr64LE::new(&key.into(), &iv.into());
|
||||||
|
cipher.apply_keystream(&mut database_data);
|
||||||
|
|
||||||
|
std::fs::write(db_path, database_data)?;
|
||||||
|
Ok(DatabaseInterface {
|
||||||
|
data: RwLock::new(database.0),
|
||||||
|
path: db_path.to_path_buf(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn database_is_set_up(&self) -> bool {
|
||||||
!borrow_db_checked().base_url.is_empty()
|
!borrow_db_checked().base_url.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_base_url(&self) -> Url {
|
pub fn fetch_base_url(&self) -> Url {
|
||||||
let handle = borrow_db_checked();
|
let handle = borrow_db_checked();
|
||||||
Url::parse(&handle.base_url)
|
Url::parse(&handle.base_url)
|
||||||
.unwrap_or_else(|_| panic!("Failed to parse base url {}", handle.base_url))
|
.unwrap_or_else(|_| panic!("Failed to parse base url {}", handle.base_url))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn save(&self) -> Result<(), Error> {
|
||||||
|
let lock = self.data.read().expect("failed to lock database to save");
|
||||||
|
DatabaseInterface::create_at_path(&self.path, lock.clone())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn borrow_data(
|
||||||
|
&self,
|
||||||
|
) -> Result<
|
||||||
|
std::sync::RwLockReadGuard<'_, Database>,
|
||||||
|
PoisonError<std::sync::RwLockReadGuard<'_, Database>>,
|
||||||
|
> {
|
||||||
|
self.data.read()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn borrow_data_mut(
|
||||||
|
&self,
|
||||||
|
) -> Result<
|
||||||
|
std::sync::RwLockWriteGuard<'_, Database>,
|
||||||
|
PoisonError<std::sync::RwLockWriteGuard<'_, Database>>,
|
||||||
|
> {
|
||||||
|
self.data.write()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make the error relelvant rather than just assume that it's a Deserialize error
|
// TODO: Make the error relelvant rather than just assume that it's a Deserialize error
|
||||||
fn handle_invalid_database(
|
fn handle_invalid_database(
|
||||||
_e: RustbreakError,
|
error: Error,
|
||||||
db_path: PathBuf,
|
db_path: PathBuf,
|
||||||
games_base_dir: PathBuf,
|
games_base_dir: PathBuf,
|
||||||
cache_dir: PathBuf,
|
cache_dir: PathBuf,
|
||||||
) -> rustbreak::Database<Database, rustbreak::backend::PathBackend, DropDatabaseSerializer> {
|
) -> Result<DatabaseInterface, Error> {
|
||||||
warn!("{_e}");
|
warn!("{error:?}");
|
||||||
let new_path = {
|
let new_path = {
|
||||||
let time = Utc::now().timestamp();
|
let time = Utc::now().timestamp();
|
||||||
let mut base = db_path.clone();
|
let mut base = db_path.clone();
|
||||||
@@ -126,7 +187,7 @@ fn handle_invalid_database(
|
|||||||
|
|
||||||
let db = Database::new(games_base_dir, Some(new_path), cache_dir);
|
let db = Database::new(games_base_dir, Some(new_path), cache_dir);
|
||||||
|
|
||||||
PathDatabase::create_at_path(db_path, db).expect("Database could not be created")
|
Ok(DatabaseInterface::create_at_path(&db_path, db).expect("Database could not be created"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// To automatically save the database upon drop
|
// To automatically save the database upon drop
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
pub mod data {
|
pub mod data {
|
||||||
use std::{hash::Hash, path::PathBuf};
|
use std::{hash::Hash, path::PathBuf};
|
||||||
|
|
||||||
use native_model::native_model;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
// NOTE: Within each version, you should NEVER use these types.
|
// NOTE: Within each version, you should NEVER use these types.
|
||||||
// Declare it using the actual version that it is from, i.e. v1::Settings rather than just Settings from here
|
// Declare it using the actual version that it is from, i.e. v1::Settings rather than just Settings from here
|
||||||
|
|
||||||
|
pub type Database = v1::Database;
|
||||||
pub type GameVersion = v1::GameVersion;
|
pub type GameVersion = v1::GameVersion;
|
||||||
pub type Database = v3::Database;
|
|
||||||
pub type Settings = v1::Settings;
|
pub type Settings = v1::Settings;
|
||||||
pub type DatabaseAuth = v1::DatabaseAuth;
|
pub type DatabaseAuth = v1::DatabaseAuth;
|
||||||
|
|
||||||
pub type GameDownloadStatus = v2::GameDownloadStatus;
|
pub type GameDownloadStatus = v1::GameDownloadStatus;
|
||||||
pub type ApplicationTransientStatus = v1::ApplicationTransientStatus;
|
pub type ApplicationTransientStatus = v1::ApplicationTransientStatus;
|
||||||
/**
|
/**
|
||||||
* Need to be universally accessible by the ID, and the version is just a couple sprinkles on top
|
* Need to be universally accessible by the ID, and the version is just a couple sprinkles on top
|
||||||
*/
|
*/
|
||||||
pub type DownloadableMetadata = v1::DownloadableMetadata;
|
pub type DownloadableMetadata = v1::DownloadableMetadata;
|
||||||
pub type DownloadType = v1::DownloadType;
|
pub type DownloadType = v1::DownloadType;
|
||||||
pub type DatabaseApplications = v2::DatabaseApplications;
|
pub type DatabaseApplications = v1::DatabaseApplications;
|
||||||
// pub type DatabaseCompatInfo = v2::DatabaseCompatInfo;
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@@ -36,13 +34,44 @@ pub mod data {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
enum DatabaseVersionEnum {
|
||||||
|
V1 { database: v1::Database },
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DatabaseVersionSerializable(pub(crate) Database);
|
||||||
|
|
||||||
|
impl Serialize for DatabaseVersionSerializable {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
// Always serialize to latest version
|
||||||
|
DatabaseVersionEnum::V1 {
|
||||||
|
database: self.0.clone(),
|
||||||
|
}
|
||||||
|
.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for DatabaseVersionSerializable {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
Ok(match DatabaseVersionEnum::deserialize(deserializer)? {
|
||||||
|
DatabaseVersionEnum::V1 { database } => DatabaseVersionSerializable(database),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mod v1 {
|
mod v1 {
|
||||||
use serde_with::serde_as;
|
use serde_with::serde_as;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
use crate::platform::Platform;
|
use crate::platform::Platform;
|
||||||
|
|
||||||
use super::{Deserialize, Serialize, native_model};
|
use super::{Deserialize, Serialize};
|
||||||
|
|
||||||
fn default_template() -> String {
|
fn default_template() -> String {
|
||||||
"{}".to_owned()
|
"{}".to_owned()
|
||||||
@@ -50,49 +79,58 @@ pub mod data {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[native_model(id = 2, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
pub struct GameVersion {
|
pub struct GameVersion {
|
||||||
pub game_id: String,
|
pub game_id: String,
|
||||||
pub version_name: String,
|
pub version_id: String,
|
||||||
|
|
||||||
pub platform: Platform,
|
pub display_name: Option<String>,
|
||||||
|
pub version_path: String,
|
||||||
pub launch_command: String,
|
|
||||||
pub launch_args: Vec<String>,
|
|
||||||
#[serde(default = "default_template")]
|
|
||||||
pub launch_command_template: String,
|
|
||||||
|
|
||||||
pub setup_command: String,
|
|
||||||
pub setup_args: Vec<String>,
|
|
||||||
#[serde(default = "default_template")]
|
|
||||||
pub setup_command_template: String,
|
|
||||||
|
|
||||||
pub only_setup: bool,
|
pub only_setup: bool,
|
||||||
|
|
||||||
pub version_index: usize,
|
pub version_index: usize,
|
||||||
pub delta: bool,
|
pub delta: bool,
|
||||||
|
|
||||||
pub umu_id_override: Option<String>,
|
#[serde(default = "default_template")]
|
||||||
|
pub launch_template: String,
|
||||||
|
|
||||||
|
pub launches: Vec<LaunchConfiguration>,
|
||||||
|
pub setups: Vec<SetupConfiguration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serde_as]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
#[derive(Serialize, Clone, Deserialize, Default)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[native_model(id = 3, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
pub struct LaunchConfiguration {
|
||||||
pub struct DatabaseApplications {
|
pub launch_id: String,
|
||||||
pub install_dirs: Vec<PathBuf>,
|
|
||||||
// Guaranteed to exist if the game also exists in the app state map
|
|
||||||
pub game_statuses: HashMap<String, GameDownloadStatus>,
|
|
||||||
pub game_versions: HashMap<String, HashMap<String, GameVersion>>,
|
|
||||||
pub installed_game_version: HashMap<String, DownloadableMetadata>,
|
|
||||||
|
|
||||||
#[serde(skip)]
|
pub name: String,
|
||||||
pub transient_statuses: HashMap<DownloadableMetadata, ApplicationTransientStatus>,
|
pub command: String,
|
||||||
|
pub platform: Platform,
|
||||||
|
pub umu_id_override: Option<String>,
|
||||||
|
|
||||||
|
pub executor: Option<LaunchConfigurationExecutor>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
/**
|
||||||
|
* This is intended to be used to look up the actual launch configuration that we store elsewhere
|
||||||
|
*/
|
||||||
|
pub struct LaunchConfigurationExecutor {
|
||||||
|
pub launch_id: String,
|
||||||
|
pub game_id: String,
|
||||||
|
pub version_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct SetupConfiguration {
|
||||||
|
pub command: String,
|
||||||
|
pub platform: Platform,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[native_model(id = 4, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub autostart: bool,
|
pub autostart: bool,
|
||||||
pub max_download_threads: usize,
|
pub max_download_threads: usize,
|
||||||
@@ -108,129 +146,8 @@ pub mod data {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strings are version names for a particular game
|
|
||||||
#[derive(Serialize, Clone, Deserialize)]
|
|
||||||
#[serde(tag = "type")]
|
|
||||||
#[native_model(id = 5, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
pub enum GameDownloadStatus {
|
|
||||||
Remote {},
|
|
||||||
SetupRequired {
|
|
||||||
version_name: String,
|
|
||||||
install_dir: String,
|
|
||||||
},
|
|
||||||
Installed {
|
|
||||||
version_name: String,
|
|
||||||
install_dir: String,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stuff that shouldn't be synced to disk
|
|
||||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
|
||||||
pub enum ApplicationTransientStatus {
|
|
||||||
Queued { version_name: String },
|
|
||||||
Downloading { version_name: String },
|
|
||||||
Uninstalling {},
|
|
||||||
Updating { version_name: String },
|
|
||||||
Validating { version_name: String },
|
|
||||||
Running {},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(serde::Serialize, Clone, Deserialize)]
|
|
||||||
#[native_model(id = 6, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
pub struct DatabaseAuth {
|
|
||||||
pub private: String,
|
|
||||||
pub cert: String,
|
|
||||||
pub client_id: String,
|
|
||||||
pub web_token: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 8, version = 1)]
|
|
||||||
#[derive(
|
|
||||||
Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Clone, Copy,
|
|
||||||
)]
|
|
||||||
pub enum DownloadType {
|
|
||||||
Game,
|
|
||||||
Tool,
|
|
||||||
Dlc,
|
|
||||||
Mod,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 7, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Debug, Eq, PartialOrd, Ord, Serialize, Deserialize, Clone)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct DownloadableMetadata {
|
|
||||||
pub id: String,
|
|
||||||
pub version: Option<String>,
|
|
||||||
pub download_type: DownloadType,
|
|
||||||
}
|
|
||||||
impl DownloadableMetadata {
|
|
||||||
pub fn new(id: String, version: Option<String>, download_type: DownloadType) -> Self {
|
|
||||||
Self {
|
|
||||||
id,
|
|
||||||
version,
|
|
||||||
download_type,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 1, version = 1)]
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
|
||||||
pub struct Database {
|
|
||||||
#[serde(default)]
|
|
||||||
pub settings: Settings,
|
|
||||||
pub auth: Option<DatabaseAuth>,
|
|
||||||
pub base_url: String,
|
|
||||||
pub applications: DatabaseApplications,
|
|
||||||
pub prev_database: Option<PathBuf>,
|
|
||||||
pub cache_dir: PathBuf,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod v2 {
|
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
|
||||||
|
|
||||||
use serde_with::serde_as;
|
|
||||||
|
|
||||||
use super::{Deserialize, Serialize, native_model, v1};
|
|
||||||
|
|
||||||
#[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::Database)]
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
|
||||||
pub struct Database {
|
|
||||||
#[serde(default)]
|
|
||||||
pub settings: v1::Settings,
|
|
||||||
pub auth: Option<v1::DatabaseAuth>,
|
|
||||||
pub base_url: String,
|
|
||||||
pub applications: v1::DatabaseApplications,
|
|
||||||
#[serde(skip)]
|
|
||||||
pub prev_database: Option<PathBuf>,
|
|
||||||
pub cache_dir: PathBuf,
|
|
||||||
pub compat_info: Option<DatabaseCompatInfo>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[native_model(id = 9, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
|
||||||
|
|
||||||
pub struct DatabaseCompatInfo {
|
|
||||||
pub umu_installed: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v1::Database> for Database {
|
|
||||||
fn from(value: v1::Database) -> Self {
|
|
||||||
Self {
|
|
||||||
settings: value.settings,
|
|
||||||
auth: value.auth,
|
|
||||||
base_url: value.base_url,
|
|
||||||
applications: value.applications,
|
|
||||||
prev_database: value.prev_database,
|
|
||||||
cache_dir: value.cache_dir,
|
|
||||||
compat_info: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Strings are version names for a particular game
|
|
||||||
#[derive(Serialize, Clone, Deserialize, Debug)]
|
#[derive(Serialize, Clone, Deserialize, Debug)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
#[native_model(id = 5, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::GameDownloadStatus)]
|
|
||||||
pub enum GameDownloadStatus {
|
pub enum GameDownloadStatus {
|
||||||
Remote {},
|
Remote {},
|
||||||
SetupRequired {
|
SetupRequired {
|
||||||
@@ -246,89 +163,84 @@ pub mod data {
|
|||||||
install_dir: String,
|
install_dir: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
impl From<v1::GameDownloadStatus> for GameDownloadStatus {
|
// Stuff that shouldn't be synced to disk
|
||||||
fn from(value: v1::GameDownloadStatus) -> Self {
|
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||||
match value {
|
pub enum ApplicationTransientStatus {
|
||||||
v1::GameDownloadStatus::Remote {} => Self::Remote {},
|
Queued { version_id: String },
|
||||||
v1::GameDownloadStatus::SetupRequired {
|
Downloading { version_id: String },
|
||||||
version_name,
|
Uninstalling {},
|
||||||
install_dir,
|
Updating { version_id: String },
|
||||||
} => Self::SetupRequired {
|
Validating { version_id: String },
|
||||||
version_name,
|
Running {},
|
||||||
install_dir,
|
}
|
||||||
},
|
|
||||||
v1::GameDownloadStatus::Installed {
|
#[derive(serde::Serialize, Clone, Deserialize)]
|
||||||
version_name,
|
pub struct DatabaseAuth {
|
||||||
install_dir,
|
pub private: String,
|
||||||
} => Self::Installed {
|
pub cert: String,
|
||||||
version_name,
|
pub client_id: String,
|
||||||
install_dir,
|
pub web_token: Option<String>,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Clone, Copy,
|
||||||
|
)]
|
||||||
|
pub enum DownloadType {
|
||||||
|
Game,
|
||||||
|
Tool,
|
||||||
|
Dlc,
|
||||||
|
Mod,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialOrd, Ord, Serialize, Deserialize, Clone)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct DownloadableMetadata {
|
||||||
|
pub id: String,
|
||||||
|
pub version: String,
|
||||||
|
pub target_platform: Platform,
|
||||||
|
pub download_type: DownloadType,
|
||||||
|
}
|
||||||
|
impl DownloadableMetadata {
|
||||||
|
pub fn new(
|
||||||
|
id: String,
|
||||||
|
version: String,
|
||||||
|
target_platform: Platform,
|
||||||
|
download_type: DownloadType,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
id,
|
||||||
|
version,
|
||||||
|
target_platform,
|
||||||
|
download_type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serde_as]
|
#[serde_as]
|
||||||
#[derive(Serialize, Clone, Deserialize, Default)]
|
#[derive(Serialize, Clone, Deserialize, Default)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[native_model(id = 3, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from=v1::DatabaseApplications)]
|
|
||||||
pub struct DatabaseApplications {
|
pub struct DatabaseApplications {
|
||||||
pub install_dirs: Vec<PathBuf>,
|
pub install_dirs: Vec<PathBuf>,
|
||||||
// Guaranteed to exist if the game also exists in the app state map
|
// Guaranteed to exist if the game also exists in the app state map
|
||||||
pub game_statuses: HashMap<String, GameDownloadStatus>,
|
pub game_statuses: HashMap<String, GameDownloadStatus>,
|
||||||
|
|
||||||
pub game_versions: HashMap<String, HashMap<String, v1::GameVersion>>,
|
pub game_versions: HashMap<String, GameVersion>,
|
||||||
pub installed_game_version: HashMap<String, v1::DownloadableMetadata>,
|
pub installed_game_version: HashMap<String, DownloadableMetadata>,
|
||||||
|
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub transient_statuses:
|
pub transient_statuses: HashMap<DownloadableMetadata, ApplicationTransientStatus>,
|
||||||
HashMap<v1::DownloadableMetadata, v1::ApplicationTransientStatus>,
|
|
||||||
}
|
}
|
||||||
impl From<v1::DatabaseApplications> for DatabaseApplications {
|
|
||||||
fn from(value: v1::DatabaseApplications) -> Self {
|
|
||||||
Self {
|
|
||||||
game_statuses: value
|
|
||||||
.game_statuses
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| (x.0, x.1.into()))
|
|
||||||
.collect::<HashMap<String, GameDownloadStatus>>(),
|
|
||||||
install_dirs: value.install_dirs,
|
|
||||||
game_versions: value.game_versions,
|
|
||||||
installed_game_version: value.installed_game_version,
|
|
||||||
transient_statuses: value.transient_statuses,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mod v3 {
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use super::{Deserialize, Serialize, native_model, v1, v2};
|
|
||||||
#[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde, from = v2::Database)]
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub settings: v1::Settings,
|
pub settings: Settings,
|
||||||
pub auth: Option<v1::DatabaseAuth>,
|
pub auth: Option<DatabaseAuth>,
|
||||||
pub base_url: String,
|
pub base_url: String,
|
||||||
pub applications: v2::DatabaseApplications,
|
pub applications: DatabaseApplications,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub prev_database: Option<PathBuf>,
|
pub prev_database: Option<PathBuf>,
|
||||||
pub cache_dir: PathBuf,
|
pub cache_dir: PathBuf,
|
||||||
pub compat_info: Option<v2::DatabaseCompatInfo>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v2::Database> for Database {
|
|
||||||
fn from(value: v2::Database) -> Self {
|
|
||||||
Self {
|
|
||||||
settings: value.settings,
|
|
||||||
auth: value.auth,
|
|
||||||
base_url: value.base_url,
|
|
||||||
applications: value.applications.into(),
|
|
||||||
prev_database: value.prev_database,
|
|
||||||
cache_dir: value.cache_dir,
|
|
||||||
compat_info: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +263,6 @@ pub mod data {
|
|||||||
auth: None,
|
auth: None,
|
||||||
settings: Settings::default(),
|
settings: Settings::default(),
|
||||||
cache_dir,
|
cache_dir,
|
||||||
compat_info: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,24 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Eq, Hash, PartialEq, Serialize, Deserialize, Clone, Copy, Debug)]
|
#[derive(Eq, Hash, PartialEq, Serialize, Deserialize, Clone, Copy, Debug, PartialOrd, Ord)]
|
||||||
pub enum Platform {
|
pub enum Platform {
|
||||||
Windows,
|
Windows,
|
||||||
Linux,
|
Linux,
|
||||||
MacOs,
|
#[allow(non_camel_case_types)]
|
||||||
|
macOS,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Platform {
|
impl Platform {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub const HOST: Platform = Self::Windows;
|
pub const HOST: Platform = Self::Windows;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub const HOST: Platform = Self::MacOs;
|
pub const HOST: Platform = Self::macOS;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub const HOST: Platform = Self::Linux;
|
pub const HOST: Platform = Self::Linux;
|
||||||
|
|
||||||
pub fn is_case_sensitive(&self) -> bool {
|
pub fn is_case_sensitive(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Windows | Self::MacOs => false,
|
Self::Windows | Self::macOS => false,
|
||||||
Self::Linux => true,
|
Self::Linux => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +29,7 @@ impl From<&str> for Platform {
|
|||||||
match value.to_lowercase().trim() {
|
match value.to_lowercase().trim() {
|
||||||
"windows" => Self::Windows,
|
"windows" => Self::Windows,
|
||||||
"linux" => Self::Linux,
|
"linux" => Self::Linux,
|
||||||
"mac" | "macos" => Self::MacOs,
|
"mac" | "macos" => Self::macOS,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +40,7 @@ impl From<whoami::Platform> for Platform {
|
|||||||
match value {
|
match value {
|
||||||
whoami::Platform::Windows => Platform::Windows,
|
whoami::Platform::Windows => Platform::Windows,
|
||||||
whoami::Platform::Linux => Platform::Linux,
|
whoami::Platform::Linux => Platform::Linux,
|
||||||
whoami::Platform::MacOS => Platform::MacOs,
|
whoami::Platform::MacOS => Platform::macOS,
|
||||||
platform => unimplemented!("Playform {} is not supported", platform),
|
platform => unimplemented!("Playform {} is not supported", platform),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,17 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
atomic-instant-full = "0.1.0"
|
async-trait = "0.1.89"
|
||||||
|
atomic-instant-full = "0.1"
|
||||||
database = { version = "0.1.0", path = "../database" }
|
database = { version = "0.1.0", path = "../database" }
|
||||||
|
futures-util = "0.3.31"
|
||||||
humansize = "2.1.3"
|
humansize = "2.1.3"
|
||||||
log = "0.4.28"
|
log = "0.4.28"
|
||||||
parking_lot = "0.12.5"
|
parking_lot = "0.12.5"
|
||||||
remote = { version = "0.1.0", path = "../remote" }
|
remote = { version = "0.1.0", path = "../remote" }
|
||||||
serde = "1.0.228"
|
serde = "1.0.228"
|
||||||
serde_with = "3.15.0"
|
serde_with = "3.15.0"
|
||||||
tauri = "2.8.5"
|
tauri = "*"
|
||||||
throttle_my_fn = "0.2.6"
|
throttle_my_fn = "0.2.6"
|
||||||
|
tokio = { version = "1.48.0", features = ["sync"] }
|
||||||
utils = { version = "0.1.0", path = "../utils" }
|
utils = { version = "0.1.0", path = "../utils" }
|
||||||
|
|||||||
144
src-tauri/download_manager/src/depot_manager.rs
Normal file
144
src-tauri/download_manager/src/depot_manager.rs
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
sync::RwLock,
|
||||||
|
time::{Duration, Instant},
|
||||||
|
};
|
||||||
|
|
||||||
|
use futures_util::StreamExt;
|
||||||
|
use remote::{
|
||||||
|
error::RemoteAccessError,
|
||||||
|
requests::{generate_url, make_authenticated_get},
|
||||||
|
utils::DROP_CLIENT_ASYNC,
|
||||||
|
};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use tauri::Url;
|
||||||
|
|
||||||
|
use crate::util::semaphore::{SyncSemaphore, SyncSemaphorePermit};
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct DepotManifestContent {
|
||||||
|
version_id: String,
|
||||||
|
//compression: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct DepotManifest {
|
||||||
|
content: HashMap<String, Vec<DepotManifestContent>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Depot {
|
||||||
|
endpoint: String,
|
||||||
|
manifest: Option<DepotManifest>,
|
||||||
|
latest_speed: Option<usize>, // bytes per second
|
||||||
|
current_downloads: SyncSemaphore,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DepotManager {
|
||||||
|
depots: RwLock<Vec<Depot>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct ServersideDepot {
|
||||||
|
endpoint: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
const SPEEDTEST_TIMEOUT: Duration = Duration::from_secs(4);
|
||||||
|
|
||||||
|
impl DepotManager {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
depots: RwLock::new(Vec::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn sync_depots(&self) -> Result<(), RemoteAccessError> {
|
||||||
|
let depots = make_authenticated_get(generate_url(&["/api/v1/client/depots"], &[])?).await?;
|
||||||
|
let depots: Vec<ServersideDepot> = depots.json().await?;
|
||||||
|
|
||||||
|
let mut new_depots = depots
|
||||||
|
.into_iter()
|
||||||
|
.map(|depot| Depot {
|
||||||
|
endpoint: if depot.endpoint.ends_with("/") {
|
||||||
|
depot.endpoint
|
||||||
|
} else {
|
||||||
|
format!("{}/", depot.endpoint)
|
||||||
|
},
|
||||||
|
manifest: None,
|
||||||
|
latest_speed: None,
|
||||||
|
current_downloads: SyncSemaphore::new(),
|
||||||
|
})
|
||||||
|
.collect::<Vec<Depot>>();
|
||||||
|
|
||||||
|
for depot in &mut new_depots {
|
||||||
|
let manifest_url = Url::parse(&depot.endpoint)?.join("manifest.json")?;
|
||||||
|
let manifest = DROP_CLIENT_ASYNC.get(manifest_url).send().await?;
|
||||||
|
let manifest: DepotManifest = manifest.json().await?;
|
||||||
|
depot.manifest.replace(manifest);
|
||||||
|
|
||||||
|
let speedtest_url = Url::parse(&depot.endpoint)?.join("speedtest")?;
|
||||||
|
let speedtest = DROP_CLIENT_ASYNC.get(speedtest_url).send().await?;
|
||||||
|
|
||||||
|
let mut stream = speedtest.bytes_stream();
|
||||||
|
let start = Instant::now();
|
||||||
|
let mut total_length = 0;
|
||||||
|
|
||||||
|
while let Some(chunk) = stream.next().await {
|
||||||
|
let length = chunk?.len();
|
||||||
|
total_length += length;
|
||||||
|
if SPEEDTEST_TIMEOUT <= start.elapsed() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let elapsed = start.elapsed().as_millis() as usize;
|
||||||
|
let speed = if elapsed == 0 { usize::MAX } else { (total_length / elapsed) * 1000 };
|
||||||
|
depot.latest_speed.replace(speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut depot_lock = self.depots.write().unwrap();
|
||||||
|
*depot_lock = new_depots;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_depot(
|
||||||
|
&self,
|
||||||
|
game_id: &str,
|
||||||
|
version_id: &str,
|
||||||
|
) -> Result<(String, SyncSemaphorePermit), RemoteAccessError> {
|
||||||
|
let lock = self.depots.read().unwrap();
|
||||||
|
let best_depot = lock
|
||||||
|
.iter()
|
||||||
|
.filter(|v| {
|
||||||
|
let manifest = match &v.manifest {
|
||||||
|
Some(v) => v,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let versions = match manifest.content.get(game_id) {
|
||||||
|
Some(v) => v,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let _version = match versions.iter().find(|v| v.version_id == version_id) {
|
||||||
|
Some(v) => v,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
|
||||||
|
true
|
||||||
|
})
|
||||||
|
.max_by(|x, y| {
|
||||||
|
let x_speed = x.latest_speed.unwrap_or(0) / x.current_downloads.permits();
|
||||||
|
let y_speed = y.latest_speed.unwrap_or(0) / y.current_downloads.permits();
|
||||||
|
x_speed.cmp(&y_speed)
|
||||||
|
})
|
||||||
|
.ok_or(RemoteAccessError::NoDepots)?;
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
best_depot.endpoint.clone(),
|
||||||
|
best_depot.current_downloads.acquire(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
|
use core::panic;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
sync::{
|
sync::{Arc, Mutex},
|
||||||
Arc, Mutex,
|
time::Duration,
|
||||||
mpsc::{Receiver, Sender, channel},
|
|
||||||
},
|
|
||||||
thread::{JoinHandle, spawn},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use database::DownloadableMetadata;
|
use database::DownloadableMetadata;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use tauri::AppHandle;
|
use tauri::{AppHandle, async_runtime::JoinHandle};
|
||||||
|
use tokio::sync::mpsc::{Receiver, Sender};
|
||||||
|
use tokio::{sync::mpsc, time::timeout};
|
||||||
use utils::{app_emit, lock, send};
|
use utils::{app_emit, lock, send};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
depot_manager::DepotManager,
|
||||||
download_manager_frontend::DownloadStatus,
|
download_manager_frontend::DownloadStatus,
|
||||||
error::ApplicationDownloadError,
|
error::ApplicationDownloadError,
|
||||||
frontend_updates::{QueueUpdateEvent, QueueUpdateEventQueueData, StatsUpdateEvent},
|
frontend_updates::{QueueUpdateEvent, QueueUpdateEventQueueData, StatsUpdateEvent},
|
||||||
@@ -83,10 +84,11 @@ pub struct DownloadManagerBuilder {
|
|||||||
impl DownloadManagerBuilder {
|
impl DownloadManagerBuilder {
|
||||||
pub fn build(app_handle: AppHandle) -> DownloadManager {
|
pub fn build(app_handle: AppHandle) -> DownloadManager {
|
||||||
let queue = Queue::new();
|
let queue = Queue::new();
|
||||||
let (command_sender, command_receiver) = channel();
|
let (command_sender, command_receiver) = mpsc::channel(1500);
|
||||||
let active_progress = Arc::new(Mutex::new(None));
|
let active_progress = Arc::new(Mutex::new(None));
|
||||||
let status = Arc::new(Mutex::new(DownloadManagerStatus::Empty));
|
let status = Arc::new(Mutex::new(DownloadManagerStatus::Empty));
|
||||||
|
|
||||||
|
let depot_manager = Arc::new(DepotManager::new());
|
||||||
let manager = Self {
|
let manager = Self {
|
||||||
download_agent_registry: HashMap::new(),
|
download_agent_registry: HashMap::new(),
|
||||||
download_queue: queue.clone(),
|
download_queue: queue.clone(),
|
||||||
@@ -100,74 +102,87 @@ impl DownloadManagerBuilder {
|
|||||||
active_control_flag: None,
|
active_control_flag: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let terminator = spawn(|| manager.manage_queue());
|
let terminator = tauri::async_runtime::spawn(async move {
|
||||||
|
let result = manager.manage_queue().await;
|
||||||
|
info!("download manager exited with result: {:?}", result);
|
||||||
|
});
|
||||||
|
|
||||||
DownloadManager::new(terminator, queue, active_progress, command_sender)
|
DownloadManager::new(terminator, queue, active_progress, command_sender, depot_manager)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_status(&self, status: DownloadManagerStatus) {
|
fn set_status(&self, status: DownloadManagerStatus) {
|
||||||
*lock!(self.status) = status;
|
*lock!(self.status) = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_and_cleanup_front_download(&mut self, meta: &DownloadableMetadata) -> DownloadAgent {
|
async fn remove_and_cleanup_front_download(
|
||||||
|
&mut self,
|
||||||
|
meta: &DownloadableMetadata,
|
||||||
|
) -> DownloadAgent {
|
||||||
self.download_queue.pop_front();
|
self.download_queue.pop_front();
|
||||||
let download_agent = self.download_agent_registry.remove(meta).unwrap();
|
let download_agent = self.download_agent_registry.remove(meta).unwrap();
|
||||||
self.cleanup_current_download();
|
self.cleanup_current_download().await;
|
||||||
download_agent
|
download_agent
|
||||||
}
|
}
|
||||||
|
|
||||||
// CAREFUL WITH THIS FUNCTION
|
// CAREFUL WITH THIS FUNCTION
|
||||||
// Make sure the download thread is terminated
|
// Make sure the download thread is terminated
|
||||||
fn cleanup_current_download(&mut self) {
|
async fn cleanup_current_download(&mut self) {
|
||||||
self.active_control_flag = None;
|
self.active_control_flag = None;
|
||||||
*lock!(self.progress) = None;
|
*lock!(self.progress) = None;
|
||||||
|
|
||||||
let mut download_thread_lock = lock!(self.current_download_thread);
|
if let Some(unfinished_thread) = {
|
||||||
|
let mut download_thread_lock = lock!(self.current_download_thread);
|
||||||
if let Some(unfinished_thread) = download_thread_lock.take()
|
download_thread_lock.take()
|
||||||
&& !unfinished_thread.is_finished()
|
} {
|
||||||
{
|
let _ = unfinished_thread.await;
|
||||||
unfinished_thread.join().unwrap();
|
|
||||||
}
|
}
|
||||||
drop(download_thread_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop_and_wait_current_download(&self) -> bool {
|
async fn stop_and_wait_current_download(&self) -> bool {
|
||||||
self.set_status(DownloadManagerStatus::Paused);
|
self.set_status(DownloadManagerStatus::Paused);
|
||||||
if let Some(current_flag) = &self.active_control_flag {
|
if let Some(current_flag) = &self.active_control_flag {
|
||||||
current_flag.set(DownloadThreadControlFlag::Stop);
|
current_flag.set(DownloadThreadControlFlag::Stop);
|
||||||
}
|
|
||||||
|
|
||||||
let mut download_thread_lock = lock!(self.current_download_thread);
|
if let Some(current_download_thread) = {
|
||||||
if let Some(current_download_thread) = download_thread_lock.take() {
|
let mut download_thread_lock = lock!(self.current_download_thread);
|
||||||
return current_download_thread.join().is_ok();
|
download_thread_lock.take()
|
||||||
};
|
} {
|
||||||
|
let result = timeout(Duration::from_secs(4), async {
|
||||||
|
current_download_thread.await.is_ok()
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
if let Ok(result) = result {
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
panic!("failed to cleanup download: timeout after 4 seconds");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn manage_queue(mut self) -> Result<(), ()> {
|
async fn manage_queue(mut self) -> Result<(), ()> {
|
||||||
loop {
|
loop {
|
||||||
let signal = match self.command_receiver.recv() {
|
let signal = match self.command_receiver.recv().await {
|
||||||
Ok(signal) => signal,
|
Some(signal) => signal,
|
||||||
Err(_) => return Err(()),
|
None => return Err(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
match signal {
|
match signal {
|
||||||
DownloadManagerSignal::Go => {
|
DownloadManagerSignal::Go => {
|
||||||
self.manage_go_signal();
|
self.manage_go_signal().await;
|
||||||
}
|
}
|
||||||
DownloadManagerSignal::Stop => {
|
DownloadManagerSignal::Stop => {
|
||||||
self.manage_stop_signal();
|
self.manage_stop_signal();
|
||||||
}
|
}
|
||||||
DownloadManagerSignal::Completed(meta) => {
|
DownloadManagerSignal::Completed(meta) => {
|
||||||
self.manage_completed_signal(meta);
|
self.manage_completed_signal(meta).await;
|
||||||
}
|
}
|
||||||
DownloadManagerSignal::Queue(download_agent) => {
|
DownloadManagerSignal::Queue(download_agent) => {
|
||||||
self.manage_queue_signal(download_agent);
|
self.manage_queue_signal(download_agent).await;
|
||||||
}
|
}
|
||||||
DownloadManagerSignal::Error(e) => {
|
DownloadManagerSignal::Error(e) => {
|
||||||
self.manage_error_signal(e);
|
self.manage_error_signal(e).await;
|
||||||
}
|
}
|
||||||
DownloadManagerSignal::UpdateUIQueue => {
|
DownloadManagerSignal::UpdateUIQueue => {
|
||||||
self.push_ui_queue_update();
|
self.push_ui_queue_update();
|
||||||
@@ -176,16 +191,16 @@ impl DownloadManagerBuilder {
|
|||||||
self.push_ui_stats_update(kbs, time);
|
self.push_ui_stats_update(kbs, time);
|
||||||
}
|
}
|
||||||
DownloadManagerSignal::Finish => {
|
DownloadManagerSignal::Finish => {
|
||||||
self.stop_and_wait_current_download();
|
self.stop_and_wait_current_download().await;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
DownloadManagerSignal::Cancel(meta) => {
|
DownloadManagerSignal::Cancel(meta) => {
|
||||||
self.manage_cancel_signal(&meta);
|
self.manage_cancel_signal(&meta).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn manage_queue_signal(&mut self, download_agent: DownloadAgent) {
|
async fn manage_queue_signal(&mut self, download_agent: DownloadAgent) {
|
||||||
debug!("got signal Queue");
|
debug!("got signal Queue");
|
||||||
let meta = download_agent.metadata();
|
let meta = download_agent.metadata();
|
||||||
|
|
||||||
@@ -203,7 +218,7 @@ impl DownloadManagerBuilder {
|
|||||||
send!(self.sender, DownloadManagerSignal::UpdateUIQueue);
|
send!(self.sender, DownloadManagerSignal::UpdateUIQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn manage_go_signal(&mut self) {
|
async fn manage_go_signal(&mut self) {
|
||||||
debug!("got signal Go");
|
debug!("got signal Go");
|
||||||
if self.download_agent_registry.is_empty() {
|
if self.download_agent_registry.is_empty() {
|
||||||
debug!(
|
debug!(
|
||||||
@@ -249,18 +264,19 @@ impl DownloadManagerBuilder {
|
|||||||
let mut download_thread_lock = lock!(self.current_download_thread);
|
let mut download_thread_lock = lock!(self.current_download_thread);
|
||||||
let app_handle = self.app_handle.clone();
|
let app_handle = self.app_handle.clone();
|
||||||
|
|
||||||
*download_thread_lock = Some(spawn(move || {
|
*download_thread_lock = Some(tauri::async_runtime::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
let download_result = match download_agent.download(&app_handle) {
|
let download_result =
|
||||||
// Ok(true) is for completed and exited properly
|
match download_agent.download(&app_handle).await {
|
||||||
Ok(v) => v,
|
// Ok(true) is for completed and exited properly
|
||||||
Err(e) => {
|
Ok(v) => v,
|
||||||
error!("download {:?} has error {}", download_agent.metadata(), &e);
|
Err(e) => {
|
||||||
download_agent.on_error(&app_handle, &e);
|
error!("download {:?} has error {}", download_agent.metadata(), &e);
|
||||||
send!(sender, DownloadManagerSignal::Error(e));
|
download_agent.on_error(&app_handle, &e);
|
||||||
return;
|
send!(sender, DownloadManagerSignal::Error(e));
|
||||||
}
|
return;
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// If the download gets canceled
|
// If the download gets canceled
|
||||||
// immediately return, on_cancelled gets called for us earlier
|
// immediately return, on_cancelled gets called for us earlier
|
||||||
@@ -291,7 +307,7 @@ impl DownloadManagerBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if validate_result {
|
if validate_result {
|
||||||
download_agent.on_complete(&app_handle);
|
download_agent.on_complete(&app_handle).await;
|
||||||
send!(
|
send!(
|
||||||
sender,
|
sender,
|
||||||
DownloadManagerSignal::Completed(download_agent.metadata())
|
DownloadManagerSignal::Completed(download_agent.metadata())
|
||||||
@@ -307,40 +323,35 @@ impl DownloadManagerBuilder {
|
|||||||
active_control_flag.set(DownloadThreadControlFlag::Go);
|
active_control_flag.set(DownloadThreadControlFlag::Go);
|
||||||
}
|
}
|
||||||
fn manage_stop_signal(&mut self) {
|
fn manage_stop_signal(&mut self) {
|
||||||
debug!("got signal Stop");
|
|
||||||
|
|
||||||
if let Some(active_control_flag) = self.active_control_flag.clone() {
|
if let Some(active_control_flag) = self.active_control_flag.clone() {
|
||||||
self.set_status(DownloadManagerStatus::Paused);
|
self.set_status(DownloadManagerStatus::Paused);
|
||||||
active_control_flag.set(DownloadThreadControlFlag::Stop);
|
active_control_flag.set(DownloadThreadControlFlag::Stop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn manage_completed_signal(&mut self, meta: DownloadableMetadata) {
|
async fn manage_completed_signal(&mut self, meta: DownloadableMetadata) {
|
||||||
debug!("got signal Completed");
|
|
||||||
if let Some(interface) = self.download_queue.read().front()
|
if let Some(interface) = self.download_queue.read().front()
|
||||||
&& interface == &meta
|
&& interface == &meta
|
||||||
{
|
{
|
||||||
self.remove_and_cleanup_front_download(&meta);
|
self.remove_and_cleanup_front_download(&meta).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.push_ui_queue_update();
|
self.push_ui_queue_update();
|
||||||
send!(self.sender, DownloadManagerSignal::Go);
|
send!(self.sender, DownloadManagerSignal::Go);
|
||||||
}
|
}
|
||||||
fn manage_error_signal(&mut self, error: ApplicationDownloadError) {
|
async fn manage_error_signal(&mut self, error: ApplicationDownloadError) {
|
||||||
debug!("got signal Error");
|
info!("got signal Error");
|
||||||
if let Some(metadata) = self.download_queue.read().front()
|
if let Some(metadata) = self.download_queue.read().front()
|
||||||
&& let Some(current_agent) = self.download_agent_registry.get(metadata)
|
&& let Some(current_agent) = self.download_agent_registry.get(metadata)
|
||||||
{
|
{
|
||||||
current_agent.on_error(&self.app_handle, &error);
|
current_agent.on_error(&self.app_handle, &error);
|
||||||
|
|
||||||
self.stop_and_wait_current_download();
|
self.stop_and_wait_current_download().await;
|
||||||
self.remove_and_cleanup_front_download(metadata);
|
self.remove_and_cleanup_front_download(metadata).await;
|
||||||
}
|
}
|
||||||
self.push_ui_queue_update();
|
self.push_ui_queue_update();
|
||||||
self.set_status(DownloadManagerStatus::Error);
|
self.set_status(DownloadManagerStatus::Error);
|
||||||
}
|
}
|
||||||
fn manage_cancel_signal(&mut self, meta: &DownloadableMetadata) {
|
async fn manage_cancel_signal(&mut self, meta: &DownloadableMetadata) {
|
||||||
debug!("got signal Cancel");
|
|
||||||
|
|
||||||
// If the current download is the one we're tryna cancel
|
// If the current download is the one we're tryna cancel
|
||||||
if let Some(current_metadata) = self.download_queue.read().front()
|
if let Some(current_metadata) = self.download_queue.read().front()
|
||||||
&& current_metadata == meta
|
&& current_metadata == meta
|
||||||
@@ -348,13 +359,13 @@ impl DownloadManagerBuilder {
|
|||||||
{
|
{
|
||||||
self.set_status(DownloadManagerStatus::Paused);
|
self.set_status(DownloadManagerStatus::Paused);
|
||||||
current_download.on_cancelled(&self.app_handle);
|
current_download.on_cancelled(&self.app_handle);
|
||||||
self.stop_and_wait_current_download();
|
self.stop_and_wait_current_download().await;
|
||||||
|
self.set_status(DownloadManagerStatus::Empty);
|
||||||
|
|
||||||
self.download_queue.pop_front();
|
self.download_queue.pop_front();
|
||||||
|
|
||||||
self.cleanup_current_download();
|
self.cleanup_current_download().await;
|
||||||
self.download_agent_registry.remove(meta);
|
self.download_agent_registry.remove(meta);
|
||||||
debug!("current download queue: {:?}", self.download_queue.read());
|
|
||||||
}
|
}
|
||||||
// else just cancel it
|
// else just cancel it
|
||||||
else if let Some(download_agent) = self.download_agent_registry.get(meta) {
|
else if let Some(download_agent) = self.download_agent_registry.get(meta) {
|
||||||
@@ -370,8 +381,8 @@ impl DownloadManagerBuilder {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.sender.send(DownloadManagerSignal::Go).unwrap();
|
|
||||||
self.push_ui_queue_update();
|
self.push_ui_queue_update();
|
||||||
|
send!(self.sender, DownloadManagerSignal::Go);
|
||||||
}
|
}
|
||||||
fn push_ui_stats_update(&self, kbs: usize, time: usize) {
|
fn push_ui_stats_update(&self, kbs: usize, time: usize) {
|
||||||
let event_data = StatsUpdateEvent { speed: kbs, time };
|
let event_data = StatsUpdateEvent { speed: kbs, time };
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
use std::{
|
use std::{
|
||||||
any::Any,
|
|
||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
sync::{
|
sync::{Arc, Mutex, MutexGuard},
|
||||||
Mutex, MutexGuard,
|
|
||||||
mpsc::{SendError, Sender},
|
|
||||||
},
|
|
||||||
thread::JoinHandle,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use database::DownloadableMetadata;
|
use database::DownloadableMetadata;
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use tauri::async_runtime::JoinHandle;
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
|
use tokio::sync::mpsc::error::SendError;
|
||||||
use utils::{lock, send};
|
use utils::{lock, send};
|
||||||
|
|
||||||
use crate::error::ApplicationDownloadError;
|
use crate::{depot_manager::DepotManager, error::ApplicationDownloadError};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
download_manager_builder::{CurrentProgressObject, DownloadAgent},
|
download_manager_builder::{CurrentProgressObject, DownloadAgent},
|
||||||
util::queue::Queue,
|
util::queue::Queue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum DownloadManagerSignal {
|
pub enum DownloadManagerSignal {
|
||||||
/// Resumes (or starts) the `DownloadManager`
|
/// Resumes (or starts) the `DownloadManager`
|
||||||
Go,
|
Go,
|
||||||
@@ -79,38 +78,47 @@ pub enum DownloadStatus {
|
|||||||
/// The actual download queue may be accessed through the .`edit()` function,
|
/// The actual download queue may be accessed through the .`edit()` function,
|
||||||
/// which provides raw access to the underlying queue.
|
/// which provides raw access to the underlying queue.
|
||||||
/// THIS EDITING IS BLOCKING!!!
|
/// THIS EDITING IS BLOCKING!!!
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct DownloadManager {
|
pub struct DownloadManager {
|
||||||
terminator: Mutex<Option<JoinHandle<Result<(), ()>>>>,
|
terminator: Mutex<Option<JoinHandle<()>>>,
|
||||||
download_queue: Queue,
|
download_queue: Queue,
|
||||||
progress: CurrentProgressObject,
|
progress: CurrentProgressObject,
|
||||||
command_sender: Sender<DownloadManagerSignal>,
|
command_sender: Sender<DownloadManagerSignal>,
|
||||||
|
depot_manager: Arc<DepotManager>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Debug for DownloadManager {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_struct("DownloadManager").finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
impl DownloadManager {
|
impl DownloadManager {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
terminator: JoinHandle<Result<(), ()>>,
|
terminator: JoinHandle<()>,
|
||||||
download_queue: Queue,
|
download_queue: Queue,
|
||||||
progress: CurrentProgressObject,
|
progress: CurrentProgressObject,
|
||||||
command_sender: Sender<DownloadManagerSignal>,
|
command_sender: Sender<DownloadManagerSignal>,
|
||||||
|
depot_manager: Arc<DepotManager>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
terminator: Mutex::new(Some(terminator)),
|
terminator: Mutex::new(Some(terminator)),
|
||||||
download_queue,
|
download_queue,
|
||||||
progress,
|
progress,
|
||||||
command_sender,
|
command_sender,
|
||||||
|
depot_manager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn queue_download(
|
pub async fn queue_download(
|
||||||
&self,
|
&self,
|
||||||
download: DownloadAgent,
|
download: DownloadAgent,
|
||||||
) -> Result<(), SendError<DownloadManagerSignal>> {
|
) -> Result<(), SendError<DownloadManagerSignal>> {
|
||||||
info!("creating download with meta {:?}", download.metadata());
|
info!("creating download with meta {:?}", download.metadata());
|
||||||
self.command_sender
|
self.command_sender
|
||||||
.send(DownloadManagerSignal::Queue(download))?;
|
.send(DownloadManagerSignal::Queue(download))
|
||||||
self.command_sender.send(DownloadManagerSignal::Go)
|
.await?;
|
||||||
|
self.command_sender.send(DownloadManagerSignal::Go).await
|
||||||
}
|
}
|
||||||
pub fn edit(&self) -> MutexGuard<'_, VecDeque<DownloadableMetadata>> {
|
pub fn edit(&self) -> MutexGuard<'_, VecDeque<DownloadableMetadata>> {
|
||||||
self.download_queue.edit()
|
self.download_queue.edit()
|
||||||
@@ -122,7 +130,7 @@ impl DownloadManager {
|
|||||||
let progress_object = (*lock!(self.progress)).clone()?;
|
let progress_object = (*lock!(self.progress)).clone()?;
|
||||||
Some(progress_object.get_progress())
|
Some(progress_object.get_progress())
|
||||||
}
|
}
|
||||||
pub fn rearrange_string(&self, meta: &DownloadableMetadata, new_index: usize) {
|
pub async fn rearrange_string(&self, meta: &DownloadableMetadata, new_index: usize) {
|
||||||
let mut queue = self.edit();
|
let mut queue = self.edit();
|
||||||
let current_index =
|
let current_index =
|
||||||
get_index_from_id(&mut queue, meta).expect("Failed to get meta index from id");
|
get_index_from_id(&mut queue, meta).expect("Failed to get meta index from id");
|
||||||
@@ -132,10 +140,10 @@ impl DownloadManager {
|
|||||||
queue.insert(new_index, to_move);
|
queue.insert(new_index, to_move);
|
||||||
send!(self.command_sender, DownloadManagerSignal::UpdateUIQueue);
|
send!(self.command_sender, DownloadManagerSignal::UpdateUIQueue);
|
||||||
}
|
}
|
||||||
pub fn cancel(&self, meta: DownloadableMetadata) {
|
pub async fn cancel(&self, meta: DownloadableMetadata) {
|
||||||
send!(self.command_sender, DownloadManagerSignal::Cancel(meta));
|
send!(self.command_sender, DownloadManagerSignal::Cancel(meta));
|
||||||
}
|
}
|
||||||
pub fn rearrange(&self, current_index: usize, new_index: usize) {
|
pub async fn rearrange(&self, current_index: usize, new_index: usize) {
|
||||||
if current_index == new_index {
|
if current_index == new_index {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -147,10 +155,11 @@ impl DownloadManager {
|
|||||||
|
|
||||||
debug!("moving download at index {current_index} to index {new_index}");
|
debug!("moving download at index {current_index} to index {new_index}");
|
||||||
|
|
||||||
let mut queue = self.edit();
|
{
|
||||||
let to_move = queue.remove(current_index).expect("Failed to get");
|
let mut queue = self.edit();
|
||||||
queue.insert(new_index, to_move);
|
let to_move = queue.remove(current_index).expect("Failed to get");
|
||||||
drop(queue);
|
queue.insert(new_index, to_move);
|
||||||
|
}
|
||||||
|
|
||||||
if needs_pause {
|
if needs_pause {
|
||||||
send!(self.command_sender, DownloadManagerSignal::Go);
|
send!(self.command_sender, DownloadManagerSignal::Go);
|
||||||
@@ -158,20 +167,23 @@ impl DownloadManager {
|
|||||||
send!(self.command_sender, DownloadManagerSignal::UpdateUIQueue);
|
send!(self.command_sender, DownloadManagerSignal::UpdateUIQueue);
|
||||||
send!(self.command_sender, DownloadManagerSignal::Go);
|
send!(self.command_sender, DownloadManagerSignal::Go);
|
||||||
}
|
}
|
||||||
pub fn pause_downloads(&self) {
|
pub async fn pause_downloads(&self) {
|
||||||
send!(self.command_sender, DownloadManagerSignal::Stop);
|
send!(self.command_sender, DownloadManagerSignal::Stop);
|
||||||
}
|
}
|
||||||
pub fn resume_downloads(&self) {
|
pub async fn resume_downloads(&self) {
|
||||||
send!(self.command_sender, DownloadManagerSignal::Go);
|
send!(self.command_sender, DownloadManagerSignal::Go);
|
||||||
}
|
}
|
||||||
pub fn ensure_terminated(&self) -> Result<Result<(), ()>, Box<dyn Any + Send>> {
|
pub async fn ensure_terminated(&self) -> Result<(), tauri::Error> {
|
||||||
send!(self.command_sender, DownloadManagerSignal::Finish);
|
send!(self.command_sender, DownloadManagerSignal::Finish);
|
||||||
let terminator = lock!(self.terminator).take();
|
let terminator = lock!(self.terminator).take();
|
||||||
terminator.unwrap().join()
|
terminator.unwrap().await
|
||||||
}
|
}
|
||||||
pub fn get_sender(&self) -> Sender<DownloadManagerSignal> {
|
pub fn get_sender(&self) -> Sender<DownloadManagerSignal> {
|
||||||
self.command_sender.clone()
|
self.command_sender.clone()
|
||||||
}
|
}
|
||||||
|
pub fn clone_depot_manager(&self) -> Arc<DepotManager> {
|
||||||
|
self.depot_manager.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes in the locked value from .`edit()` and attempts to
|
/// Takes in the locked value from .`edit()` and attempts to
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::{fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
use database::DownloadableMetadata;
|
use database::DownloadableMetadata;
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
|
|
||||||
@@ -16,8 +17,9 @@ use super::{
|
|||||||
*
|
*
|
||||||
* But the download manager manages the queue state
|
* But the download manager manages the queue state
|
||||||
*/
|
*/
|
||||||
pub trait Downloadable: Send + Sync {
|
#[async_trait]
|
||||||
fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError>;
|
pub trait Downloadable: Send + Sync + Debug {
|
||||||
|
async fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError>;
|
||||||
fn validate(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError>;
|
fn validate(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError>;
|
||||||
|
|
||||||
fn progress(&self) -> Arc<ProgressObject>;
|
fn progress(&self) -> Arc<ProgressObject>;
|
||||||
@@ -26,6 +28,6 @@ pub trait Downloadable: Send + Sync {
|
|||||||
fn metadata(&self) -> DownloadableMetadata;
|
fn metadata(&self) -> DownloadableMetadata;
|
||||||
fn on_queued(&self, app_handle: &AppHandle);
|
fn on_queued(&self, app_handle: &AppHandle);
|
||||||
fn on_error(&self, app_handle: &AppHandle, error: &ApplicationDownloadError);
|
fn on_error(&self, app_handle: &AppHandle, error: &ApplicationDownloadError);
|
||||||
fn on_complete(&self, app_handle: &AppHandle);
|
async fn on_complete(&self, app_handle: &AppHandle);
|
||||||
fn on_cancelled(&self, app_handle: &AppHandle);
|
fn on_cancelled(&self, app_handle: &AppHandle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ pub enum ApplicationDownloadError {
|
|||||||
Lock,
|
Lock,
|
||||||
IoError(Arc<io::Error>),
|
IoError(Arc<io::Error>),
|
||||||
DownloadError(RemoteAccessError),
|
DownloadError(RemoteAccessError),
|
||||||
|
InvalidCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for ApplicationDownloadError {
|
impl Display for ApplicationDownloadError {
|
||||||
@@ -69,6 +70,7 @@ impl Display for ApplicationDownloadError {
|
|||||||
ApplicationDownloadError::DownloadError(error) => {
|
ApplicationDownloadError::DownloadError(error) => {
|
||||||
write!(f, "Download failed with error {error:?}")
|
write!(f, "Download failed with error {error:?}")
|
||||||
}
|
}
|
||||||
|
ApplicationDownloadError::InvalidCommand => write!(f, "Invalid command state"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub mod downloadable;
|
|||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod frontend_updates;
|
pub mod frontend_updates;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
pub mod depot_manager;
|
||||||
|
|
||||||
pub static DOWNLOAD_MANAGER: DownloadManagerWrapper = DownloadManagerWrapper::new();
|
pub static DOWNLOAD_MANAGER: DownloadManagerWrapper = DownloadManagerWrapper::new();
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ impl DownloadManagerWrapper {
|
|||||||
DOWNLOAD_MANAGER
|
DOWNLOAD_MANAGER
|
||||||
.0
|
.0
|
||||||
.set(DownloadManagerBuilder::build(app_handle))
|
.set(DownloadManagerBuilder::build(app_handle))
|
||||||
.expect("Failed to initialise download manager");
|
.expect("failed to initialise download manager");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ pub mod download_thread_control_flag;
|
|||||||
pub mod progress_object;
|
pub mod progress_object;
|
||||||
pub mod queue;
|
pub mod queue;
|
||||||
pub mod rolling_progress_updates;
|
pub mod rolling_progress_updates;
|
||||||
|
pub mod semaphore;
|
||||||
@@ -2,14 +2,13 @@ use std::{
|
|||||||
sync::{
|
sync::{
|
||||||
Arc, Mutex,
|
Arc, Mutex,
|
||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
mpsc::Sender,
|
|
||||||
},
|
},
|
||||||
time::{Duration, Instant},
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use atomic_instant_full::AtomicInstant;
|
use atomic_instant_full::AtomicInstant;
|
||||||
use throttle_my_fn::throttle;
|
|
||||||
use utils::{lock, send};
|
use utils::{lock, send};
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
|
|
||||||
use crate::download_manager_frontend::DownloadManagerSignal;
|
use crate::download_manager_frontend::DownloadManagerSignal;
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ impl ProgressHandle {
|
|||||||
pub fn add(&self, amount: usize) {
|
pub fn add(&self, amount: usize) {
|
||||||
self.progress
|
self.progress
|
||||||
.fetch_add(amount, std::sync::atomic::Ordering::AcqRel);
|
.fetch_add(amount, std::sync::atomic::Ordering::AcqRel);
|
||||||
calculate_update(&self.progress_object);
|
tauri::async_runtime::spawn(calculate_update(self.progress_object.clone()));
|
||||||
}
|
}
|
||||||
pub fn skip(&self, amount: usize) {
|
pub fn skip(&self, amount: usize) {
|
||||||
self.progress
|
self.progress
|
||||||
@@ -112,14 +111,17 @@ impl ProgressObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[throttle(1, Duration::from_millis(20))]
|
pub async fn calculate_update(progress: Arc<ProgressObject>) {
|
||||||
pub fn calculate_update(progress: &ProgressObject) {
|
|
||||||
let last_update_time = progress
|
let last_update_time = progress
|
||||||
.last_update_time
|
.last_update_time
|
||||||
.swap(Instant::now(), Ordering::SeqCst);
|
.load(Ordering::SeqCst);
|
||||||
let time_since_last_update = Instant::now()
|
let time_since_last_update = Instant::now()
|
||||||
.duration_since(last_update_time)
|
.duration_since(last_update_time)
|
||||||
.as_millis_f64();
|
.as_millis_f64();
|
||||||
|
if time_since_last_update < 250.0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
progress.last_update_time.swap(Instant::now(), Ordering::SeqCst);
|
||||||
|
|
||||||
let current_bytes_downloaded = progress.sum();
|
let current_bytes_downloaded = progress.sum();
|
||||||
let max = progress.get_max();
|
let max = progress.get_max();
|
||||||
@@ -135,25 +137,24 @@ pub fn calculate_update(progress: &ProgressObject) {
|
|||||||
let bytes_remaining = max.saturating_sub(current_bytes_downloaded); // bytes
|
let bytes_remaining = max.saturating_sub(current_bytes_downloaded); // bytes
|
||||||
|
|
||||||
progress.update_window(kilobytes_per_second as usize);
|
progress.update_window(kilobytes_per_second as usize);
|
||||||
push_update(progress, bytes_remaining);
|
push_update(&progress, bytes_remaining).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[throttle(1, Duration::from_millis(250))]
|
pub async fn push_update(progress: &ProgressObject, bytes_remaining: usize) {
|
||||||
pub fn push_update(progress: &ProgressObject, bytes_remaining: usize) {
|
|
||||||
let average_speed = progress.rolling.get_average();
|
let average_speed = progress.rolling.get_average();
|
||||||
let time_remaining = (bytes_remaining / 1000) / average_speed.max(1);
|
let time_remaining = (bytes_remaining / 1000) / average_speed.max(1);
|
||||||
|
|
||||||
update_ui(progress, average_speed, time_remaining);
|
update_ui(progress, average_speed, time_remaining).await;
|
||||||
update_queue(progress);
|
update_queue(progress).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_ui(progress_object: &ProgressObject, kilobytes_per_second: usize, time_remaining: usize) {
|
async fn update_ui(progress_object: &ProgressObject, kilobytes_per_second: usize, time_remaining: usize) {
|
||||||
send!(
|
send!(
|
||||||
progress_object.sender,
|
progress_object.sender,
|
||||||
DownloadManagerSignal::UpdateUIStats(kilobytes_per_second, time_remaining)
|
DownloadManagerSignal::UpdateUIStats(kilobytes_per_second, time_remaining)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_queue(progress: &ProgressObject) {
|
async fn update_queue(progress: &ProgressObject) {
|
||||||
send!(progress.sender, DownloadManagerSignal::UpdateUIQueue)
|
send!(progress.sender, DownloadManagerSignal::UpdateUIQueue)
|
||||||
}
|
}
|
||||||
|
|||||||
28
src-tauri/download_manager/src/util/semaphore.rs
Normal file
28
src-tauri/download_manager/src/util/semaphore.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
|
||||||
|
|
||||||
|
pub struct SyncSemaphore {
|
||||||
|
inner: Arc<AtomicUsize>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SyncSemaphore {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self { inner: Arc::new(AtomicUsize::new(0)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn acquire(&self) -> SyncSemaphorePermit {
|
||||||
|
self.inner.fetch_add(1, Ordering::Relaxed);
|
||||||
|
SyncSemaphorePermit(self.inner.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn permits(&self) -> usize {
|
||||||
|
self.inner.fetch_add(0, Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SyncSemaphorePermit(Arc<AtomicUsize>);
|
||||||
|
|
||||||
|
impl Drop for SyncSemaphorePermit {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.fetch_sub(1, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,23 +4,34 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
aes = "0.8.4"
|
||||||
|
async-scoped = { version = "0.9.0", features = ["use-tokio"] }
|
||||||
|
async-trait = "0.1.89"
|
||||||
atomic-instant-full = "0.1.0"
|
atomic-instant-full = "0.1.0"
|
||||||
bitcode = "0.6.7"
|
bitcode = "0.6.7"
|
||||||
boxcar = "0.2.14"
|
boxcar = "0.2.14"
|
||||||
database = { version = "0.1.0", path = "../database" }
|
crossbeam-channel = "0.5.15"
|
||||||
download_manager = { version = "0.1.0", path = "../download_manager" }
|
ctr = "0.9.2"
|
||||||
|
database = { path = "../database", version = "0.1.0" }
|
||||||
|
download_manager = { path = "../download_manager", version = "0.1.0" }
|
||||||
|
droplet-rs = { git = "https://github.com/Drop-OSS/droplet-rs" }
|
||||||
|
futures-util = "*"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
log = "0.4.28"
|
log = "0.4.28"
|
||||||
md5 = "0.8.0"
|
native_model = { git = "https://github.com/Drop-OSS/native_model.git", version = "0.6.4", features = [
|
||||||
|
"rmp_serde_1_3"
|
||||||
|
] }
|
||||||
rayon = "1.11.0"
|
rayon = "1.11.0"
|
||||||
remote = { version = "0.1.0", path = "../remote" }
|
remote = { path = "../remote", version = "0.1.0" }
|
||||||
reqwest = "0.12.23"
|
reqwest = "0.12.23"
|
||||||
rustix = "1.1.2"
|
rustix = "1.1.2"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_with = "3.15.0"
|
|
||||||
sysinfo = "0.37.2"
|
|
||||||
tauri = "2.8.5"
|
|
||||||
throttle_my_fn = "0.2.6"
|
|
||||||
utils = { version = "0.1.0", path = "../utils" }
|
|
||||||
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
|
|
||||||
serde_json = "1.0.145"
|
serde_json = "1.0.145"
|
||||||
|
serde_with = "3.15.0"
|
||||||
|
sha2 = "0.10.9"
|
||||||
|
sysinfo = "0.37.2"
|
||||||
|
tauri = "*"
|
||||||
|
throttle_my_fn = "0.2.6"
|
||||||
|
tokio = { version = "*", features = ["rt", "sync"] }
|
||||||
|
tokio-util = { version = "*", features = ["io"] }
|
||||||
|
utils = { path = "../utils", version = "0.1.0" }
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ pub struct Collection {
|
|||||||
name: String,
|
name: String,
|
||||||
is_default: bool,
|
is_default: bool,
|
||||||
user_id: String,
|
user_id: String,
|
||||||
entries: Vec<CollectionObject>,
|
pub entries: Vec<CollectionObject>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, Encode, Decode)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Default, Encode, Decode)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct CollectionObject {
|
pub struct CollectionObject {
|
||||||
collection_id: String,
|
pub collection_id: String,
|
||||||
game_id: String,
|
pub game_id: String,
|
||||||
game: Game,
|
pub game: Game,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
use database::{
|
use database::{
|
||||||
ApplicationTransientStatus, DownloadType, DownloadableMetadata, borrow_db_checked,
|
ApplicationTransientStatus, DownloadableMetadata, borrow_db_checked, borrow_db_mut_checked,
|
||||||
borrow_db_mut_checked,
|
|
||||||
};
|
};
|
||||||
|
use download_manager::depot_manager::DepotManager;
|
||||||
use download_manager::download_manager_frontend::{DownloadManagerSignal, DownloadStatus};
|
use download_manager::download_manager_frontend::{DownloadManagerSignal, DownloadStatus};
|
||||||
use download_manager::downloadable::Downloadable;
|
use download_manager::downloadable::Downloadable;
|
||||||
use download_manager::error::ApplicationDownloadError;
|
use download_manager::error::ApplicationDownloadError;
|
||||||
@@ -9,60 +10,53 @@ use download_manager::util::download_thread_control_flag::{
|
|||||||
DownloadThreadControl, DownloadThreadControlFlag,
|
DownloadThreadControl, DownloadThreadControlFlag,
|
||||||
};
|
};
|
||||||
use download_manager::util::progress_object::{ProgressHandle, ProgressObject};
|
use download_manager::util::progress_object::{ProgressHandle, ProgressObject};
|
||||||
|
use droplet_rs::manifest::Manifest;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use rayon::ThreadPoolBuilder;
|
|
||||||
use remote::auth::generate_authorization_header;
|
use remote::auth::generate_authorization_header;
|
||||||
use remote::error::RemoteAccessError;
|
use remote::error::RemoteAccessError;
|
||||||
use remote::requests::generate_url;
|
use remote::requests::generate_url;
|
||||||
use remote::utils::{DROP_CLIENT_ASYNC, DROP_CLIENT_SYNC};
|
use remote::utils::DROP_CLIENT_ASYNC;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::fmt::Debug;
|
||||||
use std::fs::{OpenOptions, create_dir_all};
|
use std::mem;
|
||||||
use std::io;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
use utils::{app_emit, lock, send};
|
use utils::{app_emit, lock, send};
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
use rustix::fs::{FallocateFlags, fallocate};
|
|
||||||
|
|
||||||
use crate::downloads::manifest::{
|
|
||||||
DownloadBucket, DownloadContext, DownloadDrop, DropManifest, DropValidateContext, ManifestBody,
|
|
||||||
};
|
|
||||||
use crate::downloads::utils::get_disk_available;
|
use crate::downloads::utils::get_disk_available;
|
||||||
use crate::downloads::validate::validate_game_chunk;
|
|
||||||
use crate::library::{on_game_complete, push_game_update, set_partially_installed};
|
use crate::library::{on_game_complete, push_game_update, set_partially_installed};
|
||||||
use crate::state::GameStatusManager;
|
use crate::state::GameStatusManager;
|
||||||
|
|
||||||
use super::download_logic::download_game_bucket;
|
use super::download_logic::download_game_chunk;
|
||||||
use super::drop_data::DropData;
|
use super::drop_data::DropData;
|
||||||
|
|
||||||
static RETRY_COUNT: usize = 3;
|
static RETRY_COUNT: usize = 3;
|
||||||
|
|
||||||
const TARGET_BUCKET_SIZE: usize = 63 * 1000 * 1000;
|
|
||||||
const MAX_FILES_PER_BUCKET: usize = (1024 / 4) - 1;
|
|
||||||
|
|
||||||
pub struct GameDownloadAgent {
|
pub struct GameDownloadAgent {
|
||||||
pub id: String,
|
pub metadata: DownloadableMetadata,
|
||||||
pub version: String,
|
|
||||||
pub control_flag: DownloadThreadControl,
|
pub control_flag: DownloadThreadControl,
|
||||||
buckets: Mutex<Vec<DownloadBucket>>,
|
pub manifest: Mutex<Option<Manifest>>,
|
||||||
context_map: Mutex<HashMap<String, bool>>,
|
|
||||||
pub manifest: Mutex<Option<DropManifest>>,
|
|
||||||
pub progress: Arc<ProgressObject>,
|
pub progress: Arc<ProgressObject>,
|
||||||
|
depot_manager: Arc<DepotManager>,
|
||||||
sender: Sender<DownloadManagerSignal>,
|
sender: Sender<DownloadManagerSignal>,
|
||||||
pub dropdata: DropData,
|
pub dropdata: DropData,
|
||||||
status: Mutex<DownloadStatus>,
|
status: Mutex<DownloadStatus>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for GameDownloadAgent {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_struct("GameDownloadAgent").finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl GameDownloadAgent {
|
impl GameDownloadAgent {
|
||||||
pub async fn new_from_index(
|
pub async fn new_from_index(
|
||||||
id: String,
|
metadata: DownloadableMetadata,
|
||||||
version: String,
|
|
||||||
target_download_dir: usize,
|
target_download_dir: usize,
|
||||||
sender: Sender<DownloadManagerSignal>,
|
sender: Sender<DownloadManagerSignal>,
|
||||||
|
depot_manager: Arc<DepotManager>,
|
||||||
) -> Result<Self, ApplicationDownloadError> {
|
) -> Result<Self, ApplicationDownloadError> {
|
||||||
let base_dir = {
|
let base_dir = {
|
||||||
let db_lock = borrow_db_checked();
|
let db_lock = borrow_db_checked();
|
||||||
@@ -70,53 +64,43 @@ impl GameDownloadAgent {
|
|||||||
db_lock.applications.install_dirs[target_download_dir].clone()
|
db_lock.applications.install_dirs[target_download_dir].clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::new(id, version, base_dir, sender).await
|
Self::new(metadata, base_dir, sender, depot_manager).await
|
||||||
}
|
}
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
id: String,
|
metadata: DownloadableMetadata,
|
||||||
version: String,
|
|
||||||
base_dir: PathBuf,
|
base_dir: PathBuf,
|
||||||
sender: Sender<DownloadManagerSignal>,
|
sender: Sender<DownloadManagerSignal>,
|
||||||
|
depot_manager: Arc<DepotManager>,
|
||||||
) -> Result<Self, ApplicationDownloadError> {
|
) -> Result<Self, ApplicationDownloadError> {
|
||||||
// Don't run by default
|
// Don't run by default
|
||||||
let control_flag = DownloadThreadControl::new(DownloadThreadControlFlag::Stop);
|
let control_flag = DownloadThreadControl::new(DownloadThreadControlFlag::Stop);
|
||||||
|
|
||||||
let base_dir_path = Path::new(&base_dir);
|
let base_dir_path = Path::new(&base_dir);
|
||||||
let data_base_dir_path = base_dir_path.join(id.clone());
|
info!("base dir {}", base_dir_path.display());
|
||||||
|
let data_base_dir_path = base_dir_path.join(metadata.id.clone());
|
||||||
let stored_manifest =
|
info!("data dir path {}", data_base_dir_path.display());
|
||||||
DropData::generate(id.clone(), version.clone(), data_base_dir_path.clone());
|
|
||||||
|
|
||||||
let context_lock = stored_manifest.contexts.lock().unwrap().clone();
|
|
||||||
|
|
||||||
|
let stored_manifest = DropData::generate(
|
||||||
|
metadata.id.clone(),
|
||||||
|
metadata.version.clone(),
|
||||||
|
metadata.target_platform,
|
||||||
|
data_base_dir_path.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
let result = Self {
|
let result = Self {
|
||||||
id,
|
metadata,
|
||||||
version,
|
|
||||||
control_flag,
|
control_flag,
|
||||||
manifest: Mutex::new(None),
|
manifest: Mutex::new(None),
|
||||||
buckets: Mutex::new(Vec::new()),
|
|
||||||
context_map: Mutex::new(HashMap::new()),
|
|
||||||
progress: Arc::new(ProgressObject::new(0, 0, sender.clone())),
|
progress: Arc::new(ProgressObject::new(0, 0, sender.clone())),
|
||||||
sender,
|
sender,
|
||||||
dropdata: stored_manifest,
|
dropdata: stored_manifest,
|
||||||
status: Mutex::new(DownloadStatus::Queued),
|
status: Mutex::new(DownloadStatus::Queued),
|
||||||
|
depot_manager,
|
||||||
};
|
};
|
||||||
|
|
||||||
result.ensure_manifest_exists().await?;
|
result.ensure_manifest_exists().await?;
|
||||||
|
|
||||||
let required_space = lock!(result.manifest)
|
let required_space = lock!(result.manifest).as_ref().unwrap().size;
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.values()
|
|
||||||
.map(|e| {
|
|
||||||
e.lengths
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|(i, _)| *context_lock.get(&e.checksums[*i]).unwrap_or(&false))
|
|
||||||
.map(|(_, v)| v)
|
|
||||||
.sum::<usize>()
|
|
||||||
})
|
|
||||||
.sum::<usize>() as u64;
|
|
||||||
|
|
||||||
let available_space = get_disk_available(data_base_dir_path)? as u64;
|
let available_space = get_disk_available(data_base_dir_path)? as u64;
|
||||||
|
|
||||||
@@ -134,7 +118,7 @@ impl GameDownloadAgent {
|
|||||||
pub fn setup_download(&self, app_handle: &AppHandle) -> Result<(), ApplicationDownloadError> {
|
pub fn setup_download(&self, app_handle: &AppHandle) -> Result<(), ApplicationDownloadError> {
|
||||||
let mut db_lock = borrow_db_mut_checked();
|
let mut db_lock = borrow_db_mut_checked();
|
||||||
let status = ApplicationTransientStatus::Downloading {
|
let status = ApplicationTransientStatus::Downloading {
|
||||||
version_name: self.version.clone(),
|
version_id: self.metadata.version.clone(),
|
||||||
};
|
};
|
||||||
db_lock
|
db_lock
|
||||||
.applications
|
.applications
|
||||||
@@ -147,25 +131,26 @@ impl GameDownloadAgent {
|
|||||||
return Err(ApplicationDownloadError::NotInitialized);
|
return Err(ApplicationDownloadError::NotInitialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ensure_buckets()?;
|
|
||||||
|
|
||||||
self.control_flag.set(DownloadThreadControlFlag::Go);
|
self.control_flag.set(DownloadThreadControlFlag::Go);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blocking
|
// Blocking
|
||||||
pub fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
pub async fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
||||||
self.setup_download(app_handle)?;
|
self.setup_download(app_handle)?;
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
|
|
||||||
info!("beginning download for {}...", self.metadata().id);
|
info!("beginning download for {}...", self.metadata().id);
|
||||||
|
|
||||||
let res = self.run().map_err(ApplicationDownloadError::Communication);
|
let res = self
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
|
.map_err(ApplicationDownloadError::Communication);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"{} took {}ms to download",
|
"{} took {}ms to download",
|
||||||
self.id,
|
self.metadata.id,
|
||||||
timer.elapsed().as_millis()
|
timer.elapsed().as_millis()
|
||||||
);
|
);
|
||||||
res
|
res
|
||||||
@@ -187,7 +172,10 @@ impl GameDownloadAgent {
|
|||||||
let client = DROP_CLIENT_ASYNC.clone();
|
let client = DROP_CLIENT_ASYNC.clone();
|
||||||
let url = generate_url(
|
let url = generate_url(
|
||||||
&["/api/v1/client/game/manifest"],
|
&["/api/v1/client/game/manifest"],
|
||||||
&[("id", &self.id), ("version", &self.version)],
|
&[
|
||||||
|
("id", &self.metadata.id),
|
||||||
|
("version", &self.metadata.version),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
.map_err(ApplicationDownloadError::Communication)?;
|
.map_err(ApplicationDownloadError::Communication)?;
|
||||||
|
|
||||||
@@ -207,7 +195,7 @@ impl GameDownloadAgent {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let manifest_download: DropManifest = response
|
let manifest_download: Manifest = response
|
||||||
.json()
|
.json()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ApplicationDownloadError::Communication(e.into()))?;
|
.map_err(|e| ApplicationDownloadError::Communication(e.into()))?;
|
||||||
@@ -222,332 +210,159 @@ impl GameDownloadAgent {
|
|||||||
|
|
||||||
// Sets it up for both download and validate
|
// Sets it up for both download and validate
|
||||||
fn setup_progress(&self) {
|
fn setup_progress(&self) {
|
||||||
let buckets = lock!(self.buckets);
|
let manifest = lock!(self.manifest);
|
||||||
|
let manifest = manifest.as_ref().unwrap();
|
||||||
|
|
||||||
let chunk_count = buckets.iter().map(|e| e.drops.len()).sum();
|
self.progress.set_max(manifest.size.try_into().unwrap());
|
||||||
|
self.progress.set_size(manifest.chunks.len());
|
||||||
let total_length = buckets
|
|
||||||
.iter()
|
|
||||||
.map(|bucket| bucket.drops.iter().map(|e| e.length).sum::<usize>())
|
|
||||||
.sum();
|
|
||||||
|
|
||||||
self.progress.set_max(total_length);
|
|
||||||
self.progress.set_size(chunk_count);
|
|
||||||
self.progress.reset();
|
self.progress.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ensure_buckets(&self) -> Result<(), ApplicationDownloadError> {
|
async fn run(&self) -> Result<bool, RemoteAccessError> {
|
||||||
if lock!(self.buckets).is_empty() {
|
self.depot_manager.sync_depots().await?;
|
||||||
self.generate_buckets()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
*lock!(self.context_map) = self.dropdata.get_contexts();
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate_buckets(&self) -> Result<(), ApplicationDownloadError> {
|
|
||||||
let manifest = lock!(self.manifest)
|
|
||||||
.clone()
|
|
||||||
.ok_or(ApplicationDownloadError::NotInitialized)?;
|
|
||||||
let game_id = self.id.clone();
|
|
||||||
|
|
||||||
let base_path = Path::new(&self.dropdata.base_path);
|
|
||||||
create_dir_all(base_path)?;
|
|
||||||
|
|
||||||
let mut buckets = Vec::new();
|
|
||||||
|
|
||||||
let mut current_buckets = HashMap::<String, DownloadBucket>::new();
|
|
||||||
let mut current_bucket_sizes = HashMap::<String, usize>::new();
|
|
||||||
|
|
||||||
for (raw_path, chunk) in manifest {
|
|
||||||
let path = base_path.join(Path::new(&raw_path));
|
|
||||||
|
|
||||||
let container = path
|
|
||||||
.parent()
|
|
||||||
.ok_or(ApplicationDownloadError::IoError(Arc::new(io::Error::new(
|
|
||||||
io::ErrorKind::NotFound,
|
|
||||||
"no parent directory",
|
|
||||||
))))?;
|
|
||||||
create_dir_all(container)?;
|
|
||||||
|
|
||||||
let already_exists = path.exists();
|
|
||||||
let file = OpenOptions::new()
|
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.truncate(false)
|
|
||||||
.open(&path)?;
|
|
||||||
let mut file_running_offset = 0;
|
|
||||||
|
|
||||||
for (index, length) in chunk.lengths.iter().enumerate() {
|
|
||||||
let drop = DownloadDrop {
|
|
||||||
filename: raw_path.to_string(),
|
|
||||||
start: file_running_offset,
|
|
||||||
length: *length,
|
|
||||||
checksum: chunk.checksums[index].clone(),
|
|
||||||
permissions: chunk.permissions,
|
|
||||||
path: path.clone(),
|
|
||||||
index,
|
|
||||||
};
|
|
||||||
file_running_offset += *length;
|
|
||||||
|
|
||||||
if *length >= TARGET_BUCKET_SIZE {
|
|
||||||
// They get their own bucket
|
|
||||||
|
|
||||||
buckets.push(DownloadBucket {
|
|
||||||
game_id: game_id.clone(),
|
|
||||||
version: chunk.version_name.clone(),
|
|
||||||
drops: vec![drop],
|
|
||||||
});
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let current_bucket_size = current_bucket_sizes
|
|
||||||
.entry(chunk.version_name.clone())
|
|
||||||
.or_insert_with(|| 0);
|
|
||||||
let c_version_name = chunk.version_name.clone();
|
|
||||||
let c_game_id = game_id.clone();
|
|
||||||
let current_bucket = current_buckets
|
|
||||||
.entry(chunk.version_name.clone())
|
|
||||||
.or_insert_with(|| DownloadBucket {
|
|
||||||
game_id: c_game_id,
|
|
||||||
version: c_version_name,
|
|
||||||
drops: vec![],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (*current_bucket_size + length >= TARGET_BUCKET_SIZE
|
|
||||||
|| current_bucket.drops.len() >= MAX_FILES_PER_BUCKET)
|
|
||||||
&& !current_bucket.drops.is_empty()
|
|
||||||
{
|
|
||||||
// Move current bucket into list and make a new one
|
|
||||||
buckets.push(current_bucket.clone());
|
|
||||||
*current_bucket = DownloadBucket {
|
|
||||||
game_id: game_id.clone(),
|
|
||||||
version: chunk.version_name.clone(),
|
|
||||||
drops: vec![],
|
|
||||||
};
|
|
||||||
*current_bucket_size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
current_bucket.drops.push(drop);
|
|
||||||
*current_bucket_size += *length;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
if file_running_offset > 0 && !already_exists {
|
|
||||||
let _ = fallocate(file, FallocateFlags::empty(), 0, file_running_offset as u64);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (_, bucket) in current_buckets.into_iter() {
|
|
||||||
if !bucket.drops.is_empty() {
|
|
||||||
buckets.push(bucket);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("buckets: {}", buckets.len());
|
|
||||||
|
|
||||||
let existing_contexts = self.dropdata.get_contexts();
|
|
||||||
self.dropdata.set_contexts(
|
|
||||||
&buckets
|
|
||||||
.iter()
|
|
||||||
.flat_map(|x| x.drops.iter().map(|v| v.checksum.clone()))
|
|
||||||
.map(|x| {
|
|
||||||
let contains = existing_contexts.get(&x).unwrap_or(&false);
|
|
||||||
(x, *contains)
|
|
||||||
})
|
|
||||||
.collect::<Vec<(String, bool)>>(),
|
|
||||||
);
|
|
||||||
|
|
||||||
*lock!(self.buckets) = buckets;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run(&self) -> Result<bool, RemoteAccessError> {
|
|
||||||
self.setup_progress();
|
self.setup_progress();
|
||||||
|
let (chunks, key) = {
|
||||||
|
let manifest = lock!(self.manifest);
|
||||||
|
let manifest = manifest.as_ref().unwrap();
|
||||||
|
(manifest.chunks.clone(), manifest.key)
|
||||||
|
};
|
||||||
|
let chunk_len = chunks.len();
|
||||||
|
let mut completed_chunks = {
|
||||||
|
let completed_chunks = lock!(self.dropdata.contexts);
|
||||||
|
completed_chunks.clone()
|
||||||
|
};
|
||||||
let max_download_threads = borrow_db_checked().settings.max_download_threads;
|
let max_download_threads = borrow_db_checked().settings.max_download_threads;
|
||||||
|
|
||||||
debug!(
|
let (sender, recv) = crossbeam_channel::bounded(16);
|
||||||
"downloading game: {} with {} threads",
|
|
||||||
self.id, max_download_threads
|
|
||||||
);
|
|
||||||
let pool = ThreadPoolBuilder::new()
|
|
||||||
.num_threads(max_download_threads)
|
|
||||||
.build()
|
|
||||||
.unwrap_or_else(|_| {
|
|
||||||
panic!("failed to build thread pool with {max_download_threads} threads")
|
|
||||||
});
|
|
||||||
|
|
||||||
let buckets = lock!(self.buckets);
|
let unsafe_self: &'static GameDownloadAgent = unsafe { mem::transmute(self) };
|
||||||
|
let local_completed_chunks = completed_chunks.clone();
|
||||||
|
|
||||||
let mut download_contexts = HashMap::<String, DownloadContext>::new();
|
let download_join_handle = tauri::async_runtime::spawn_blocking(move || {
|
||||||
|
let thread_pool = rayon::ThreadPoolBuilder::new()
|
||||||
|
.num_threads(max_download_threads)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
thread_pool.scope(move |s| {
|
||||||
|
for (index, (chunk_id, chunk_data)) in chunks.into_iter().enumerate() {
|
||||||
|
let local_sender = sender.clone();
|
||||||
|
let progress = unsafe_self.progress.get(index);
|
||||||
|
let progress_handle =
|
||||||
|
ProgressHandle::new(progress, unsafe_self.progress.clone());
|
||||||
|
|
||||||
let versions = buckets
|
let chunk_length = chunk_data.files.iter().map(|v| v.length).sum();
|
||||||
.iter()
|
|
||||||
.map(|e| &e.version)
|
|
||||||
.collect::<HashSet<_>>()
|
|
||||||
.into_iter()
|
|
||||||
.cloned()
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
|
|
||||||
info!("downloading across these versions: {versions:?}");
|
if *local_completed_chunks.get(&chunk_id).unwrap_or(&false) {
|
||||||
|
progress_handle.skip(chunk_length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let completed_contexts = Arc::new(boxcar::Vec::new());
|
let sender = unsafe_self.sender.clone();
|
||||||
let completed_indexes_loop_arc = completed_contexts.clone();
|
let (depot, permit) = match unsafe_self
|
||||||
|
.depot_manager
|
||||||
for version in versions {
|
.next_depot(&unsafe_self.metadata.id, &unsafe_self.metadata.version)
|
||||||
let download_context = DROP_CLIENT_SYNC
|
{
|
||||||
.post(generate_url(&["/api/v2/client/context"], &[])?)
|
Ok(v) => v,
|
||||||
.json(&ManifestBody {
|
Err(err) => {
|
||||||
game: self.id.clone(),
|
tauri::async_runtime::spawn(async move {
|
||||||
version: version.clone(),
|
send!(sender, DownloadManagerSignal::Error(ApplicationDownloadError::Communication(err)));
|
||||||
})
|
});
|
||||||
.header("Authorization", generate_authorization_header())
|
return;
|
||||||
.send()?;
|
|
||||||
|
|
||||||
if download_context.status() != 200 {
|
|
||||||
return Err(RemoteAccessError::InvalidResponse(download_context.json()?));
|
|
||||||
}
|
|
||||||
|
|
||||||
let download_context = download_context.json::<DownloadContext>()?;
|
|
||||||
info!(
|
|
||||||
"download context: ({}) {}",
|
|
||||||
&version, download_context.context
|
|
||||||
);
|
|
||||||
download_contexts.insert(version, download_context);
|
|
||||||
}
|
|
||||||
|
|
||||||
let download_contexts = &download_contexts;
|
|
||||||
|
|
||||||
pool.scope(|scope| {
|
|
||||||
let context_map = lock!(self.context_map);
|
|
||||||
for (index, bucket) in buckets.iter().enumerate() {
|
|
||||||
let mut bucket = (*bucket).clone();
|
|
||||||
let completed_contexts = completed_indexes_loop_arc.clone();
|
|
||||||
|
|
||||||
let progress = self.progress.get(index);
|
|
||||||
let progress_handle = ProgressHandle::new(progress, self.progress.clone());
|
|
||||||
|
|
||||||
// If we've done this one already, skip it
|
|
||||||
// Note to future DecDuck, DropData gets loaded into context_map
|
|
||||||
let todo_drops = bucket
|
|
||||||
.drops
|
|
||||||
.into_iter()
|
|
||||||
.filter(|e| {
|
|
||||||
let todo = !*context_map.get(&e.checksum).unwrap_or(&false);
|
|
||||||
if !todo {
|
|
||||||
progress_handle.skip(e.length);
|
|
||||||
}
|
}
|
||||||
todo
|
};
|
||||||
})
|
|
||||||
.collect::<Vec<DownloadDrop>>();
|
|
||||||
|
|
||||||
if todo_drops.is_empty() {
|
s.spawn(move |_| {
|
||||||
continue;
|
for i in 0..RETRY_COUNT {
|
||||||
};
|
let loop_progress_handle = progress_handle.clone();
|
||||||
|
let base_path = unsafe_self.dropdata.base_path.clone();
|
||||||
bucket.drops = todo_drops;
|
match download_game_chunk(
|
||||||
|
&unsafe_self.metadata.id,
|
||||||
let sender = self.sender.clone();
|
&unsafe_self.metadata.version,
|
||||||
|
&chunk_id,
|
||||||
let download_context =
|
&depot,
|
||||||
download_contexts.get(&bucket.version).unwrap_or_else(|| {
|
&key,
|
||||||
panic!(
|
&chunk_data,
|
||||||
"Could not get bucket version {}. Corrupted state.",
|
base_path,
|
||||||
bucket.version
|
&unsafe_self.control_flag,
|
||||||
)
|
loop_progress_handle,
|
||||||
});
|
) {
|
||||||
|
Ok(true) => {
|
||||||
scope.spawn(move |_| {
|
local_sender.send(chunk_id.clone()).unwrap();
|
||||||
// 3 attempts
|
drop(permit); // Take ownership
|
||||||
for i in 0..RETRY_COUNT {
|
|
||||||
let loop_progress_handle = progress_handle.clone();
|
|
||||||
match download_game_bucket(
|
|
||||||
&bucket,
|
|
||||||
download_context,
|
|
||||||
&self.control_flag,
|
|
||||||
loop_progress_handle,
|
|
||||||
) {
|
|
||||||
Ok(true) => {
|
|
||||||
for drop in bucket.drops {
|
|
||||||
completed_contexts.push(drop.checksum);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Ok(false) => return,
|
|
||||||
Err(e) => {
|
|
||||||
warn!("game download agent error: {e}");
|
|
||||||
|
|
||||||
let retry = matches!(
|
|
||||||
&e,
|
|
||||||
ApplicationDownloadError::Communication(_)
|
|
||||||
| ApplicationDownloadError::Checksum
|
|
||||||
| ApplicationDownloadError::Lock
|
|
||||||
| ApplicationDownloadError::IoError(_)
|
|
||||||
);
|
|
||||||
|
|
||||||
if i == RETRY_COUNT - 1 || !retry {
|
|
||||||
warn!("retry logic failed, not re-attempting.");
|
|
||||||
send!(sender, DownloadManagerSignal::Error(e));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Ok(false) => return,
|
||||||
|
Err(e) => {
|
||||||
|
warn!("got error for chunk id {}: {e:?}", chunk_id);
|
||||||
|
|
||||||
|
let retry = true; /*matches!(
|
||||||
|
&e,
|
||||||
|
ApplicationDownloadError::Communication(_)
|
||||||
|
| ApplicationDownloadError::Checksum
|
||||||
|
| ApplicationDownloadError::Lock
|
||||||
|
| ApplicationDownloadError::IoError(_)
|
||||||
|
);*/
|
||||||
|
|
||||||
|
if i == RETRY_COUNT - 1 || !retry {
|
||||||
|
warn!("retry logic failed, not re-attempting.");
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
send!(sender, DownloadManagerSignal::Error(e));
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
drop(sender);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let newly_completed = completed_contexts.clone();
|
let mut outputs = Vec::new();
|
||||||
|
while let Ok(chunk_id) = recv.recv() {
|
||||||
|
outputs.push(chunk_id);
|
||||||
|
}
|
||||||
|
|
||||||
let completed_lock_len = {
|
download_join_handle
|
||||||
let mut context_map_lock = lock!(self.context_map);
|
.await
|
||||||
for (_, item) in newly_completed.iter() {
|
.expect("failed to complete download");
|
||||||
context_map_lock.insert(item.clone(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
context_map_lock.values().filter(|x| **x).count()
|
for completed_chunk in outputs {
|
||||||
};
|
completed_chunks.insert(completed_chunk, true);
|
||||||
|
}
|
||||||
|
|
||||||
let context_map_lock = lock!(self.context_map);
|
let drop_data_chunks = completed_chunks
|
||||||
let contexts = buckets
|
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|x| x.drops.iter().map(|e| e.checksum.clone()))
|
.map(|v| (v.0.to_string(), *v.1))
|
||||||
.map(|x| {
|
|
||||||
let completed = context_map_lock.get(&x).unwrap_or(&false);
|
|
||||||
(x, *completed)
|
|
||||||
})
|
|
||||||
.collect::<Vec<(String, bool)>>();
|
.collect::<Vec<(String, bool)>>();
|
||||||
drop(context_map_lock);
|
|
||||||
|
|
||||||
self.dropdata.set_contexts(&contexts);
|
self.dropdata.set_contexts(&drop_data_chunks);
|
||||||
self.dropdata.write();
|
self.dropdata.write();
|
||||||
|
|
||||||
|
info!("completed {} chunks", drop_data_chunks.len());
|
||||||
|
|
||||||
// If there are any contexts left which are false
|
// If there are any contexts left which are false
|
||||||
if !contexts.iter().all(|x| x.1) {
|
if completed_chunks.len() != chunk_len {
|
||||||
info!(
|
info!(
|
||||||
"download agent for {} exited without completing ({}/{}) ({} buckets)",
|
"download agent for {} exited without completing ({}/{})",
|
||||||
self.id.clone(),
|
self.metadata.id.clone(),
|
||||||
completed_lock_len,
|
completed_chunks.len(),
|
||||||
contexts.len(),
|
chunk_len,
|
||||||
buckets.len()
|
|
||||||
);
|
);
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn setup_validate(&self, app_handle: &AppHandle) {
|
fn setup_validate(&self, app_handle: &AppHandle) {
|
||||||
self.setup_progress();
|
self.setup_progress();
|
||||||
|
|
||||||
self.control_flag.set(DownloadThreadControlFlag::Go);
|
self.control_flag.set(DownloadThreadControlFlag::Go);
|
||||||
|
|
||||||
let status = ApplicationTransientStatus::Validating {
|
let status = ApplicationTransientStatus::Validating {
|
||||||
version_name: self.version.clone(),
|
version_id: self.metadata.version.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut db_lock = borrow_db_mut_checked();
|
let mut db_lock = borrow_db_mut_checked();
|
||||||
@@ -558,7 +373,8 @@ impl GameDownloadAgent {
|
|||||||
push_game_update(app_handle, &self.metadata().id, None, (None, Some(status)));
|
push_game_update(app_handle, &self.metadata().id, None, (None, Some(status)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validate(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
pub fn validate(&self, _app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
||||||
|
/*
|
||||||
self.setup_validate(app_handle);
|
self.setup_validate(app_handle);
|
||||||
|
|
||||||
let buckets = lock!(self.buckets);
|
let buckets = lock!(self.buckets);
|
||||||
@@ -612,6 +428,7 @@ impl GameDownloadAgent {
|
|||||||
|
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
@@ -628,10 +445,11 @@ impl GameDownloadAgent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
impl Downloadable for GameDownloadAgent {
|
impl Downloadable for GameDownloadAgent {
|
||||||
fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
async fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
||||||
*lock!(self.status) = DownloadStatus::Downloading;
|
*lock!(self.status) = DownloadStatus::Downloading;
|
||||||
self.download(app_handle)
|
self.download(app_handle).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
fn validate(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
|
||||||
@@ -648,24 +466,20 @@ impl Downloadable for GameDownloadAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn metadata(&self) -> DownloadableMetadata {
|
fn metadata(&self) -> DownloadableMetadata {
|
||||||
DownloadableMetadata {
|
self.metadata.clone()
|
||||||
id: self.id.clone(),
|
|
||||||
version: Some(self.version.clone()),
|
|
||||||
download_type: DownloadType::Game,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_queued(&self, app_handle: &tauri::AppHandle) {
|
fn on_queued(&self, app_handle: &tauri::AppHandle) {
|
||||||
*self.status.lock().unwrap() = DownloadStatus::Queued;
|
*self.status.lock().unwrap() = DownloadStatus::Queued;
|
||||||
let mut db_lock = borrow_db_mut_checked();
|
let mut db_lock = borrow_db_mut_checked();
|
||||||
let status = ApplicationTransientStatus::Queued {
|
let status = ApplicationTransientStatus::Queued {
|
||||||
version_name: self.version.clone(),
|
version_id: self.metadata.version.clone(),
|
||||||
};
|
};
|
||||||
db_lock
|
db_lock
|
||||||
.applications
|
.applications
|
||||||
.transient_statuses
|
.transient_statuses
|
||||||
.insert(self.metadata(), status.clone());
|
.insert(self.metadata(), status.clone());
|
||||||
push_game_update(app_handle, &self.id, None, (None, Some(status)));
|
push_game_update(app_handle, &self.metadata.id, None, (None, Some(status)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_error(&self, app_handle: &tauri::AppHandle, error: &ApplicationDownloadError) {
|
fn on_error(&self, app_handle: &tauri::AppHandle, error: &ApplicationDownloadError) {
|
||||||
@@ -682,18 +496,20 @@ impl Downloadable for GameDownloadAgent {
|
|||||||
|
|
||||||
push_game_update(
|
push_game_update(
|
||||||
app_handle,
|
app_handle,
|
||||||
&self.id,
|
&self.metadata.id,
|
||||||
None,
|
None,
|
||||||
GameStatusManager::fetch_state(&self.id, &handle),
|
GameStatusManager::fetch_state(&self.metadata.id, &handle),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_complete(&self, app_handle: &tauri::AppHandle) {
|
async fn on_complete(&self, app_handle: &tauri::AppHandle) {
|
||||||
match on_game_complete(
|
match on_game_complete(
|
||||||
&self.metadata(),
|
&self.metadata(),
|
||||||
self.dropdata.base_path.to_string_lossy().to_string(),
|
self.dropdata.base_path.to_string_lossy().to_string(),
|
||||||
app_handle,
|
app_handle,
|
||||||
) {
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("could not mark game as complete: {e}");
|
error!("could not mark game as complete: {e}");
|
||||||
@@ -706,7 +522,6 @@ impl Downloadable for GameDownloadAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_cancelled(&self, app_handle: &tauri::AppHandle) {
|
fn on_cancelled(&self, app_handle: &tauri::AppHandle) {
|
||||||
info!("cancelled {}", self.id);
|
|
||||||
self.cancel(app_handle);
|
self.cancel(app_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,174 +1,38 @@
|
|||||||
use std::fs::{Permissions, set_permissions};
|
use std::fs::{Permissions, set_permissions};
|
||||||
use std::io::Read;
|
use std::io::{Read, Seek as _, SeekFrom, Write as _};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::{
|
|
||||||
fs::{File, OpenOptions},
|
|
||||||
io::{self, BufWriter, Seek, SeekFrom, Write},
|
|
||||||
path::PathBuf,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
use aes::cipher::{KeyIvInit, StreamCipher};
|
||||||
use download_manager::error::ApplicationDownloadError;
|
use download_manager::error::ApplicationDownloadError;
|
||||||
use download_manager::util::download_thread_control_flag::{
|
use download_manager::util::download_thread_control_flag::{
|
||||||
DownloadThreadControl, DownloadThreadControlFlag,
|
DownloadThreadControl, DownloadThreadControlFlag,
|
||||||
};
|
};
|
||||||
use download_manager::util::progress_object::ProgressHandle;
|
use download_manager::util::progress_object::ProgressHandle;
|
||||||
use log::{debug, info, warn};
|
use droplet_rs::manifest::ChunkData;
|
||||||
use md5::{Context, Digest};
|
use log::{debug, info};
|
||||||
use remote::auth::generate_authorization_header;
|
use remote::auth::generate_authorization_header;
|
||||||
use remote::error::{DropServerError, RemoteAccessError};
|
use remote::error::{DropServerError, RemoteAccessError};
|
||||||
use remote::requests::generate_url;
|
|
||||||
use remote::utils::DROP_CLIENT_SYNC;
|
use remote::utils::DROP_CLIENT_SYNC;
|
||||||
use reqwest::blocking::Response;
|
use sha2::Digest;
|
||||||
|
use tauri::Url;
|
||||||
|
|
||||||
use crate::downloads::manifest::{ChunkBody, DownloadBucket, DownloadContext, DownloadDrop};
|
const READ_BUF_LEN: usize = 1024 * 1024;
|
||||||
|
|
||||||
static MAX_PACKET_LENGTH: usize = 4096 * 4;
|
type Aes128Ctr64LE = ctr::Ctr64LE<aes::Aes128>;
|
||||||
static BUMP_SIZE: usize = 4096 * 16;
|
|
||||||
|
|
||||||
pub struct DropWriter<W: Write> {
|
#[allow(clippy::too_many_arguments)]
|
||||||
hasher: Context,
|
pub fn download_game_chunk(
|
||||||
destination: BufWriter<W>,
|
game_id: &str,
|
||||||
progress: ProgressHandle,
|
version_id: &str,
|
||||||
}
|
chunk_id: &str,
|
||||||
impl DropWriter<File> {
|
depot: &str,
|
||||||
fn new(path: PathBuf, progress: ProgressHandle) -> Result<Self, io::Error> {
|
key: &[u8; 16],
|
||||||
let destination = OpenOptions::new()
|
chunk_data: &ChunkData,
|
||||||
.write(true)
|
base_path: PathBuf,
|
||||||
.create(true)
|
|
||||||
.truncate(false)
|
|
||||||
.open(&path)?;
|
|
||||||
Ok(Self {
|
|
||||||
destination: BufWriter::with_capacity(1024 * 1024, destination),
|
|
||||||
hasher: Context::new(),
|
|
||||||
progress,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finish(mut self) -> io::Result<Digest> {
|
|
||||||
self.flush()?;
|
|
||||||
Ok(self.hasher.finalize())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Write automatically pushes to file and hasher
|
|
||||||
impl Write for DropWriter<File> {
|
|
||||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
|
||||||
self.hasher
|
|
||||||
.write_all(buf)
|
|
||||||
.map_err(|e| io::Error::other(format!("Unable to write to hasher: {e}")))?;
|
|
||||||
let bytes_written = self.destination.write(buf)?;
|
|
||||||
self.progress.add(bytes_written);
|
|
||||||
|
|
||||||
Ok(bytes_written)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> io::Result<()> {
|
|
||||||
self.hasher.flush()?;
|
|
||||||
self.destination.flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Seek moves around destination output
|
|
||||||
impl Seek for DropWriter<File> {
|
|
||||||
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
|
|
||||||
self.destination.seek(pos)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DropDownloadPipeline<'a, R: Read, W: Write> {
|
|
||||||
pub source: R,
|
|
||||||
pub drops: Vec<DownloadDrop>,
|
|
||||||
pub destination: Vec<DropWriter<W>>,
|
|
||||||
pub control_flag: &'a DownloadThreadControl,
|
|
||||||
#[allow(dead_code)]
|
|
||||||
progress: ProgressHandle,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> DropDownloadPipeline<'a, Response, File> {
|
|
||||||
fn new(
|
|
||||||
source: Response,
|
|
||||||
drops: Vec<DownloadDrop>,
|
|
||||||
control_flag: &'a DownloadThreadControl,
|
|
||||||
progress: ProgressHandle,
|
|
||||||
) -> Result<Self, io::Error> {
|
|
||||||
Ok(Self {
|
|
||||||
source,
|
|
||||||
destination: drops
|
|
||||||
.iter()
|
|
||||||
.map(|drop| DropWriter::new(drop.path.clone(), progress.clone()))
|
|
||||||
.try_collect()?,
|
|
||||||
drops,
|
|
||||||
control_flag,
|
|
||||||
progress,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn copy(&mut self) -> Result<bool, io::Error> {
|
|
||||||
let mut copy_buffer = [0u8; MAX_PACKET_LENGTH];
|
|
||||||
for (index, drop) in self.drops.iter().enumerate() {
|
|
||||||
let destination = self
|
|
||||||
.destination
|
|
||||||
.get_mut(index)
|
|
||||||
.ok_or(io::Error::other("no destination"))?;
|
|
||||||
let mut remaining = drop.length;
|
|
||||||
if drop.start != 0 {
|
|
||||||
destination.seek(SeekFrom::Start(drop.start as u64))?;
|
|
||||||
}
|
|
||||||
let mut last_bump = 0;
|
|
||||||
loop {
|
|
||||||
let size = MAX_PACKET_LENGTH.min(remaining);
|
|
||||||
let size = self
|
|
||||||
.source
|
|
||||||
.read(&mut copy_buffer[0..size])
|
|
||||||
.inspect_err(|_| {
|
|
||||||
info!("got error from {}", drop.filename);
|
|
||||||
})?;
|
|
||||||
remaining -= size;
|
|
||||||
last_bump += size;
|
|
||||||
|
|
||||||
destination.write_all(©_buffer[0..size])?;
|
|
||||||
|
|
||||||
if last_bump > BUMP_SIZE {
|
|
||||||
last_bump -= BUMP_SIZE;
|
|
||||||
if self.control_flag.get() == DownloadThreadControlFlag::Stop {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if remaining == 0 {
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.control_flag.get() == DownloadThreadControlFlag::Stop {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn debug_skip_checksum(self) {
|
|
||||||
self.destination
|
|
||||||
.into_iter()
|
|
||||||
.for_each(|mut e| e.flush().unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finish(self) -> Result<Vec<Digest>, io::Error> {
|
|
||||||
let checksums = self
|
|
||||||
.destination
|
|
||||||
.into_iter()
|
|
||||||
.map(|e| e.finish())
|
|
||||||
.try_collect()?;
|
|
||||||
Ok(checksums)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn download_game_bucket(
|
|
||||||
bucket: &DownloadBucket,
|
|
||||||
ctx: &DownloadContext,
|
|
||||||
control_flag: &DownloadThreadControl,
|
control_flag: &DownloadThreadControl,
|
||||||
progress: ProgressHandle,
|
progress: ProgressHandle,
|
||||||
) -> Result<bool, ApplicationDownloadError> {
|
) -> Result<bool, ApplicationDownloadError> {
|
||||||
@@ -182,14 +46,16 @@ pub fn download_game_bucket(
|
|||||||
|
|
||||||
let header = generate_authorization_header();
|
let header = generate_authorization_header();
|
||||||
|
|
||||||
let url = generate_url(&["/api/v2/client/chunk"], &[])
|
let url = Url::parse(depot)
|
||||||
.map_err(ApplicationDownloadError::Communication)?;
|
.map_err(|v| ApplicationDownloadError::DownloadError(v.into()))?
|
||||||
|
.join(&format!(
|
||||||
let body = ChunkBody::create(ctx, &bucket.drops);
|
"content/{}/{}/{}",
|
||||||
|
game_id, version_id, chunk_id
|
||||||
|
))
|
||||||
|
.map_err(|v| ApplicationDownloadError::DownloadError(v.into()))?;
|
||||||
|
|
||||||
let response = DROP_CLIENT_SYNC
|
let response = DROP_CLIENT_SYNC
|
||||||
.post(url)
|
.get(url)
|
||||||
.json(&body)
|
|
||||||
.header("Authorization", header)
|
.header("Authorization", header)
|
||||||
.send()
|
.send()
|
||||||
.map_err(|e| ApplicationDownloadError::Communication(e.into()))?;
|
.map_err(|e| ApplicationDownloadError::Communication(e.into()))?;
|
||||||
@@ -197,7 +63,7 @@ pub fn download_game_bucket(
|
|||||||
if response.status() != 200 {
|
if response.status() != 200 {
|
||||||
info!("chunk request got status code: {}", response.status());
|
info!("chunk request got status code: {}", response.status());
|
||||||
let raw_res = response.text().map_err(|e| {
|
let raw_res = response.text().map_err(|e| {
|
||||||
ApplicationDownloadError::Communication(RemoteAccessError::FetchError(e.into()))
|
ApplicationDownloadError::Communication(RemoteAccessError::FetchErrorLegacy(e.into()))
|
||||||
})?;
|
})?;
|
||||||
info!("{raw_res}");
|
info!("{raw_res}");
|
||||||
if let Ok(err) = serde_json::from_str::<DropServerError>(&raw_res) {
|
if let Ok(err) = serde_json::from_str::<DropServerError>(&raw_res) {
|
||||||
@@ -210,85 +76,70 @@ pub fn download_game_bucket(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let lengths = response
|
if control_flag.get() == DownloadThreadControlFlag::Stop {
|
||||||
.headers()
|
progress.set(0);
|
||||||
.get("Content-Lengths")
|
return Ok(false);
|
||||||
.ok_or(ApplicationDownloadError::Communication(
|
|
||||||
RemoteAccessError::UnparseableResponse("missing Content-Lengths header".to_owned()),
|
|
||||||
))?
|
|
||||||
.to_str()
|
|
||||||
.map_err(|e| {
|
|
||||||
ApplicationDownloadError::Communication(RemoteAccessError::UnparseableResponse(
|
|
||||||
e.to_string(),
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
for (i, raw_length) in lengths.split(",").enumerate() {
|
|
||||||
let length = raw_length.parse::<usize>().unwrap_or(0);
|
|
||||||
let Some(drop) = bucket.drops.get(i) else {
|
|
||||||
warn!("invalid number of Content-Lengths recieved: {i}, {lengths}");
|
|
||||||
return Err(ApplicationDownloadError::DownloadError(
|
|
||||||
RemoteAccessError::InvalidResponse(DropServerError {
|
|
||||||
status_code: 400,
|
|
||||||
status_message: format!(
|
|
||||||
"invalid number of Content-Lengths recieved: {i}, {lengths}"
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
));
|
|
||||||
};
|
|
||||||
if drop.length != length {
|
|
||||||
warn!(
|
|
||||||
"for {}, expected {}, got {} ({})",
|
|
||||||
drop.filename, drop.length, raw_length, length
|
|
||||||
);
|
|
||||||
return Err(ApplicationDownloadError::DownloadError(
|
|
||||||
RemoteAccessError::InvalidResponse(DropServerError {
|
|
||||||
status_code: 400,
|
|
||||||
status_message: format!(
|
|
||||||
"for {}, expected {}, got {} ({})",
|
|
||||||
drop.filename, drop.length, raw_length, length
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let timestep = start.elapsed().as_millis();
|
let timestep = start.elapsed().as_millis();
|
||||||
|
|
||||||
debug!("took {}ms to start downloading", timestep);
|
debug!("took {}ms to start downloading", timestep);
|
||||||
|
|
||||||
let mut pipeline =
|
/*let stream = response
|
||||||
DropDownloadPipeline::new(response, bucket.drops.clone(), control_flag, progress)
|
.bytes_stream()
|
||||||
.map_err(|e| ApplicationDownloadError::IoError(Arc::new(e)))?;
|
.map(|v| v.map_err(|err| std::io::Error::other(err)));
|
||||||
|
let mut stream_reader = StreamReader::new(stream);*/
|
||||||
|
let mut stream_reader = response;
|
||||||
|
|
||||||
let completed = pipeline
|
let mut hasher = sha2::Sha256::new();
|
||||||
.copy()
|
let mut cipher = Aes128Ctr64LE::new(key.into(), &chunk_data.iv.into());
|
||||||
.map_err(|e| ApplicationDownloadError::IoError(Arc::new(e)))?;
|
let mut read_buf = vec![0u8; READ_BUF_LEN];
|
||||||
if !completed {
|
for file in &chunk_data.files {
|
||||||
return Ok(false);
|
let path = base_path.join(file.filename.clone());
|
||||||
}
|
if let Some(parent) = path.parent() {
|
||||||
|
std::fs::create_dir_all(parent)?;
|
||||||
|
}
|
||||||
|
let mut file_handle = std::fs::OpenOptions::new()
|
||||||
|
.truncate(false)
|
||||||
|
.write(true)
|
||||||
|
.append(false)
|
||||||
|
.create(true)
|
||||||
|
.open(&path)?;
|
||||||
|
file_handle.seek(SeekFrom::Start(file.start.try_into().unwrap()))?;
|
||||||
|
|
||||||
// If we complete the file, set the permissions (if on Linux)
|
let mut remaining = file.length;
|
||||||
#[cfg(unix)]
|
while remaining > 0 {
|
||||||
{
|
let amount = stream_reader.read(&mut read_buf[0..remaining.min(READ_BUF_LEN)])?;
|
||||||
for drop in bucket.drops.iter() {
|
progress.add(amount);
|
||||||
let permissions = Permissions::from_mode(drop.permissions);
|
remaining -= amount;
|
||||||
set_permissions(drop.path.clone(), permissions)
|
|
||||||
|
cipher.apply_keystream(&mut read_buf[0..amount]);
|
||||||
|
hasher.update(&read_buf[0..amount]);
|
||||||
|
file_handle.write_all(&read_buf[0..amount])?;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
drop(file_handle);
|
||||||
|
let permissions = if file.permissions == 0 {
|
||||||
|
0o744
|
||||||
|
} else {
|
||||||
|
file.permissions
|
||||||
|
};
|
||||||
|
let permissions = Permissions::from_mode(permissions);
|
||||||
|
set_permissions(path, permissions)
|
||||||
.map_err(|e| ApplicationDownloadError::IoError(Arc::new(e)))?;
|
.map_err(|e| ApplicationDownloadError::IoError(Arc::new(e)))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if control_flag.get() == DownloadThreadControlFlag::Stop {
|
||||||
|
progress.set(0);
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let checksums = pipeline
|
let digest = hex::encode(hasher.finalize());
|
||||||
.finish()
|
if digest != chunk_data.checksum {
|
||||||
.map_err(|e| ApplicationDownloadError::IoError(Arc::new(e)))?;
|
return Err(ApplicationDownloadError::Checksum);
|
||||||
|
|
||||||
for (index, drop) in bucket.drops.iter().enumerate() {
|
|
||||||
let res = hex::encode(**checksums.get(index).unwrap());
|
|
||||||
if res != drop.checksum {
|
|
||||||
warn!("context didn't match... doing nothing because we will validate later.");
|
|
||||||
// return Ok(false);
|
|
||||||
// return Err(ApplicationDownloadError::Checksum);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
|
|||||||
@@ -5,17 +5,19 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use database::platform::Platform;
|
||||||
use log::error;
|
use log::error;
|
||||||
use native_model::{Decode, Encode};
|
use native_model::{Decode, Encode};
|
||||||
use utils::lock;
|
use utils::lock;
|
||||||
|
|
||||||
pub type DropData = v1::DropData;
|
pub type DropData = v1::DropData;
|
||||||
|
|
||||||
pub static DROP_DATA_PATH: &str = ".dropdata";
|
pub static DROPDATA_PATH: &str = ".dropdata";
|
||||||
|
|
||||||
pub mod v1 {
|
pub mod v1 {
|
||||||
use std::{collections::HashMap, path::PathBuf, sync::Mutex};
|
use std::{collections::HashMap, path::PathBuf, sync::Mutex};
|
||||||
|
|
||||||
|
use database::platform::Platform;
|
||||||
use native_model::native_model;
|
use native_model::native_model;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -24,16 +26,18 @@ pub mod v1 {
|
|||||||
pub struct DropData {
|
pub struct DropData {
|
||||||
pub game_id: String,
|
pub game_id: String,
|
||||||
pub game_version: String,
|
pub game_version: String,
|
||||||
|
pub target_platform: Platform,
|
||||||
pub contexts: Mutex<HashMap<String, bool>>,
|
pub contexts: Mutex<HashMap<String, bool>>,
|
||||||
pub base_path: PathBuf,
|
pub base_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DropData {
|
impl DropData {
|
||||||
pub fn new(game_id: String, game_version: String, base_path: PathBuf) -> Self {
|
pub fn new(game_id: String, game_version: String, target_platform: Platform, base_path: PathBuf) -> Self {
|
||||||
Self {
|
Self {
|
||||||
base_path,
|
base_path,
|
||||||
game_id,
|
game_id,
|
||||||
game_version,
|
game_version,
|
||||||
|
target_platform,
|
||||||
contexts: Mutex::new(HashMap::new()),
|
contexts: Mutex::new(HashMap::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,14 +45,14 @@ pub mod v1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DropData {
|
impl DropData {
|
||||||
pub fn generate(game_id: String, game_version: String, base_path: PathBuf) -> Self {
|
pub fn generate(game_id: String, game_version: String, target_platform: Platform, base_path: PathBuf) -> Self {
|
||||||
match DropData::read(&base_path) {
|
match DropData::read(&base_path) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(_) => DropData::new(game_id, game_version, base_path),
|
Err(_) => DropData::new(game_id, game_version, target_platform, base_path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn read(base_path: &Path) -> Result<Self, io::Error> {
|
pub fn read(base_path: &Path) -> Result<Self, io::Error> {
|
||||||
let mut file = File::open(base_path.join(DROP_DATA_PATH))?;
|
let mut file = File::open(base_path.join(DROPDATA_PATH))?;
|
||||||
|
|
||||||
let mut s = Vec::new();
|
let mut s = Vec::new();
|
||||||
file.read_to_end(&mut s)?;
|
file.read_to_end(&mut s)?;
|
||||||
@@ -66,7 +70,7 @@ impl DropData {
|
|||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut file = match File::create(self.base_path.join(DROP_DATA_PATH)) {
|
let mut file = match File::create(self.base_path.join(DROPDATA_PATH)) {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("{e}");
|
error!("{e}");
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
@@ -21,57 +20,6 @@ pub struct DownloadBucket {
|
|||||||
pub drops: Vec<DownloadDrop>,
|
pub drops: Vec<DownloadDrop>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct DownloadContext {
|
|
||||||
pub context: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct ChunkBodyFile {
|
|
||||||
filename: String,
|
|
||||||
chunk_index: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct ChunkBody {
|
|
||||||
pub context: String,
|
|
||||||
pub files: Vec<ChunkBodyFile>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
pub struct ManifestBody {
|
|
||||||
pub game: String,
|
|
||||||
pub version: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ChunkBody {
|
|
||||||
pub fn create(context: &DownloadContext, drops: &[DownloadDrop]) -> ChunkBody {
|
|
||||||
Self {
|
|
||||||
context: context.context.clone(),
|
|
||||||
files: drops
|
|
||||||
.iter()
|
|
||||||
.map(|e| ChunkBodyFile {
|
|
||||||
filename: e.filename.clone(),
|
|
||||||
chunk_index: e.index,
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type DropManifest = HashMap<String, DropChunk>;
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct DropChunk {
|
|
||||||
pub permissions: u32,
|
|
||||||
pub ids: Vec<String>,
|
|
||||||
pub checksums: Vec<String>,
|
|
||||||
pub lengths: Vec<usize>,
|
|
||||||
pub version_name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct DropValidateContext {
|
pub struct DropValidateContext {
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
|
|||||||
@@ -3,5 +3,4 @@ mod download_logic;
|
|||||||
pub mod drop_data;
|
pub mod drop_data;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
mod manifest;
|
mod manifest;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod validate;
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
use std::{
|
|
||||||
fs::File,
|
|
||||||
io::{self, BufWriter, Read, Seek, SeekFrom, Write},
|
|
||||||
};
|
|
||||||
|
|
||||||
use download_manager::{
|
|
||||||
error::ApplicationDownloadError,
|
|
||||||
util::{
|
|
||||||
download_thread_control_flag::{DownloadThreadControl, DownloadThreadControlFlag},
|
|
||||||
progress_object::ProgressHandle,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use log::debug;
|
|
||||||
use md5::Context;
|
|
||||||
|
|
||||||
use crate::downloads::manifest::DropValidateContext;
|
|
||||||
|
|
||||||
pub fn validate_game_chunk(
|
|
||||||
ctx: &DropValidateContext,
|
|
||||||
control_flag: &DownloadThreadControl,
|
|
||||||
progress: ProgressHandle,
|
|
||||||
) -> Result<bool, ApplicationDownloadError> {
|
|
||||||
debug!(
|
|
||||||
"Starting chunk validation {}, {}, {} #{}",
|
|
||||||
ctx.path.display(),
|
|
||||||
ctx.index,
|
|
||||||
ctx.offset,
|
|
||||||
ctx.checksum
|
|
||||||
);
|
|
||||||
// If we're paused
|
|
||||||
if control_flag.get() == DownloadThreadControlFlag::Stop {
|
|
||||||
progress.set(0);
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
let Ok(mut source) = File::open(&ctx.path) else {
|
|
||||||
return Ok(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
if ctx.offset != 0 {
|
|
||||||
source
|
|
||||||
.seek(SeekFrom::Start(ctx.offset as u64))
|
|
||||||
.expect("Failed to seek to file offset");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut hasher = md5::Context::new();
|
|
||||||
|
|
||||||
let completed = validate_copy(&mut source, &mut hasher, ctx.length, control_flag, progress)?;
|
|
||||||
if !completed {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = hex::encode(hasher.finalize().0);
|
|
||||||
if res != ctx.checksum {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
"Successfully finished verification #{}, copied {} bytes",
|
|
||||||
ctx.checksum, ctx.length
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn validate_copy(
|
|
||||||
source: &mut File,
|
|
||||||
dest: &mut Context,
|
|
||||||
size: usize,
|
|
||||||
control_flag: &DownloadThreadControl,
|
|
||||||
progress: ProgressHandle,
|
|
||||||
) -> Result<bool, io::Error> {
|
|
||||||
let copy_buf_size = 512;
|
|
||||||
let mut copy_buf = vec![0; copy_buf_size];
|
|
||||||
let mut buf_writer = BufWriter::with_capacity(1024 * 1024, dest);
|
|
||||||
let mut total_bytes = 0;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if control_flag.get() == DownloadThreadControlFlag::Stop {
|
|
||||||
buf_writer.flush()?;
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut bytes_read = source.read(&mut copy_buf)?;
|
|
||||||
total_bytes += bytes_read;
|
|
||||||
|
|
||||||
// If we read over (likely), truncate our read to
|
|
||||||
// the right size
|
|
||||||
if total_bytes > size {
|
|
||||||
let over = total_bytes - size;
|
|
||||||
bytes_read -= over;
|
|
||||||
total_bytes = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf_writer.write_all(©_buf[0..bytes_read])?;
|
|
||||||
progress.add(bytes_read);
|
|
||||||
|
|
||||||
if total_bytes >= size {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buf_writer.flush()?;
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#![feature(iterator_try_collect)]
|
#![feature(iterator_try_collect)]
|
||||||
|
#![feature(lock_value_accessors)]
|
||||||
|
|
||||||
pub mod collections;
|
pub mod collections;
|
||||||
pub mod downloads;
|
pub mod downloads;
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ use database::{
|
|||||||
};
|
};
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use remote::{
|
use remote::{
|
||||||
auth::generate_authorization_header, error::RemoteAccessError, requests::generate_url,
|
auth::generate_authorization_header,
|
||||||
utils::DROP_CLIENT_SYNC,
|
error::RemoteAccessError,
|
||||||
|
requests::generate_url,
|
||||||
|
utils::DROP_CLIENT_ASYNC
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
@@ -18,9 +20,9 @@ use crate::state::{GameStatusManager, GameStatusWithTransient};
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct FetchGameStruct {
|
pub struct FetchGameStruct {
|
||||||
game: Game,
|
pub game: Game,
|
||||||
status: GameStatusWithTransient,
|
pub status: GameStatusWithTransient,
|
||||||
version: Option<GameVersion>,
|
pub version: Option<GameVersion>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FetchGameStruct {
|
impl FetchGameStruct {
|
||||||
@@ -36,17 +38,19 @@ impl FetchGameStruct {
|
|||||||
#[derive(Serialize, Deserialize, Clone, Debug, Default, Encode, Decode)]
|
#[derive(Serialize, Deserialize, Clone, Debug, Default, Encode, Decode)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Game {
|
pub struct Game {
|
||||||
id: String,
|
pub id: String,
|
||||||
m_name: String,
|
#[serde(rename = "type")]
|
||||||
m_short_description: String,
|
pub game_type: String,
|
||||||
m_description: String,
|
pub m_name: String,
|
||||||
|
pub m_short_description: String,
|
||||||
|
pub m_description: String,
|
||||||
// mDevelopers
|
// mDevelopers
|
||||||
// mPublishers
|
// mPublishers
|
||||||
m_icon_object_id: String,
|
pub m_icon_object_id: String,
|
||||||
m_banner_object_id: String,
|
pub m_banner_object_id: String,
|
||||||
m_cover_object_id: String,
|
pub m_cover_object_id: String,
|
||||||
m_image_library_object_ids: Vec<String>,
|
pub m_image_library_object_ids: Vec<String>,
|
||||||
m_image_carousel_object_ids: Vec<String>,
|
pub m_image_carousel_object_ids: Vec<String>,
|
||||||
}
|
}
|
||||||
impl Game {
|
impl Game {
|
||||||
pub fn id(&self) -> &String {
|
pub fn id(&self) -> &String {
|
||||||
@@ -87,7 +91,7 @@ pub fn set_partially_installed_db(
|
|||||||
db_lock.applications.game_statuses.insert(
|
db_lock.applications.game_statuses.insert(
|
||||||
meta.id.clone(),
|
meta.id.clone(),
|
||||||
GameDownloadStatus::PartiallyInstalled {
|
GameDownloadStatus::PartiallyInstalled {
|
||||||
version_name: meta.version.as_ref().unwrap().clone(),
|
version_name: meta.version.clone(),
|
||||||
install_dir,
|
install_dir,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -193,38 +197,29 @@ pub fn get_current_meta(game_id: &String) -> Option<DownloadableMetadata> {
|
|||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_game_complete(
|
pub async fn on_game_complete(
|
||||||
meta: &DownloadableMetadata,
|
meta: &DownloadableMetadata,
|
||||||
install_dir: String,
|
install_dir: String,
|
||||||
app_handle: &AppHandle,
|
app_handle: &AppHandle,
|
||||||
) -> Result<(), RemoteAccessError> {
|
) -> Result<(), RemoteAccessError> {
|
||||||
// Fetch game version information from remote
|
// Fetch game version information from remote
|
||||||
if meta.version.is_none() {
|
|
||||||
return Err(RemoteAccessError::GameNotFound(meta.id.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let client = DROP_CLIENT_SYNC.clone();
|
|
||||||
let response = generate_url(
|
let response = generate_url(
|
||||||
&["/api/v1/client/game/version"],
|
&["/api/v1/client/game", &meta.id, "version", &meta.version],
|
||||||
&[
|
&[],
|
||||||
("id", &meta.id),
|
|
||||||
("version", meta.version.as_ref().unwrap()),
|
|
||||||
],
|
|
||||||
)?;
|
)?;
|
||||||
let response = client
|
let response = DROP_CLIENT_ASYNC
|
||||||
.get(response)
|
.get(response)
|
||||||
.header("Authorization", generate_authorization_header())
|
.header("Authorization", generate_authorization_header())
|
||||||
.send()?;
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
let game_version: GameVersion = response.json()?;
|
let game_version: GameVersion = response.json().await?;
|
||||||
|
|
||||||
let mut handle = borrow_db_mut_checked();
|
let mut handle = borrow_db_mut_checked();
|
||||||
handle
|
handle
|
||||||
.applications
|
.applications
|
||||||
.game_versions
|
.game_versions
|
||||||
.entry(meta.id.clone())
|
.insert(meta.version.clone(), game_version.clone());
|
||||||
.or_default()
|
|
||||||
.insert(meta.version.clone().unwrap(), game_version.clone());
|
|
||||||
handle
|
handle
|
||||||
.applications
|
.applications
|
||||||
.installed_game_version
|
.installed_game_version
|
||||||
@@ -232,14 +227,19 @@ pub fn on_game_complete(
|
|||||||
|
|
||||||
drop(handle);
|
drop(handle);
|
||||||
|
|
||||||
let status = if game_version.setup_command.is_empty() {
|
let setup_configuration = game_version
|
||||||
|
.setups
|
||||||
|
.iter()
|
||||||
|
.find(|v| v.platform == meta.target_platform);
|
||||||
|
|
||||||
|
let status = if setup_configuration.is_none() {
|
||||||
GameDownloadStatus::Installed {
|
GameDownloadStatus::Installed {
|
||||||
version_name: meta.version.clone().unwrap(),
|
version_name: meta.version.clone(),
|
||||||
install_dir,
|
install_dir,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GameDownloadStatus::SetupRequired {
|
GameDownloadStatus::SetupRequired {
|
||||||
version_name: meta.version.clone().unwrap(),
|
version_name: meta.version.clone(),
|
||||||
install_dir,
|
install_dir,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -260,6 +260,8 @@ pub fn on_game_complete(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app_emit!(app_handle, "update_library", ());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use database::{DownloadType, DownloadableMetadata, borrow_db_mut_checked};
|
|||||||
use log::warn;
|
use log::warn;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
downloads::drop_data::{DROP_DATA_PATH, DropData},
|
downloads::drop_data::{DROPDATA_PATH, DropData},
|
||||||
library::set_partially_installed_db,
|
library::set_partially_installed_db,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ pub fn scan_install_dirs() {
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
for game in files.into_iter().flatten() {
|
for game in files.into_iter().flatten() {
|
||||||
let drop_data_file = game.path().join(DROP_DATA_PATH);
|
let drop_data_file = game.path().join(DROPDATA_PATH);
|
||||||
if !drop_data_file.exists() {
|
if !drop_data_file.exists() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,8 @@ pub fn scan_install_dirs() {
|
|||||||
|
|
||||||
let metadata = DownloadableMetadata::new(
|
let metadata = DownloadableMetadata::new(
|
||||||
drop_data.game_id,
|
drop_data.game_id,
|
||||||
Some(drop_data.game_version),
|
drop_data.game_version,
|
||||||
|
drop_data.target_platform,
|
||||||
DownloadType::Game,
|
DownloadType::Game,
|
||||||
);
|
);
|
||||||
set_partially_installed_db(
|
set_partially_installed_db(
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user