mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 00:31:33 +10:00
Compare commits
6 Commits
3b09dcfb73
...
bigpicture
| Author | SHA1 | Date | |
|---|---|---|---|
| 31f7d5bcfa | |||
| 87bbe1da49 | |||
| ab9e06f6c4 | |||
| dbf9c8e8e5 | |||
| 864640d6ae | |||
| e29d5c8ead |
2
.gitignore
vendored
2
.gitignore
vendored
@ -30,3 +30,5 @@ src-tauri/perf*
|
|||||||
|
|
||||||
/*.AppImage
|
/*.AppImage
|
||||||
/squashfs-root
|
/squashfs-root
|
||||||
|
|
||||||
|
/target/
|
||||||
|
|||||||
@ -7,14 +7,7 @@
|
|||||||
</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";
|
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
|||||||
@ -2,9 +2,7 @@
|
|||||||
<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">
|
||||||
<NuxtLink to="/store">
|
|
||||||
<Wordmark class="h-8 mb-0.5" />
|
<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
|
||||||
|
|||||||
@ -76,7 +76,6 @@ 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);
|
||||||
|
|||||||
@ -73,7 +73,7 @@
|
|||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="inline-flex items-center gap-x-2">
|
<div class="flex flex-col gap-x-2">
|
||||||
<p
|
<p
|
||||||
class="text-sm whitespace-nowrap font-display font-semibold"
|
class="text-sm whitespace-nowrap font-display font-semibold"
|
||||||
>
|
>
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
<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>
|
|
||||||
@ -9,13 +9,17 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
css: ["~/assets/main.scss"],
|
|
||||||
|
|
||||||
ssr: false,
|
ssr: false,
|
||||||
|
|
||||||
extends: [["../libs/drop-base"]],
|
extends: ["../shared", "../libs/drop-base"],
|
||||||
|
|
||||||
app: {
|
app: {
|
||||||
baseURL: "/main",
|
baseURL: "/main",
|
||||||
}
|
},
|
||||||
|
|
||||||
|
devtools: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -7,6 +7,7 @@ export default {
|
|||||||
"./plugins/**/*.{js,ts}",
|
"./plugins/**/*.{js,ts}",
|
||||||
"./app.vue",
|
"./app.vue",
|
||||||
"./error.vue",
|
"./error.vue",
|
||||||
|
"../shared/components/**/*.vue"
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {
|
extend: {
|
||||||
|
|||||||
50
shared/app.vue
Normal file
50
shared/app.vue
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<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>
|
||||||
84
shared/assets/main.scss
Normal file
84
shared/assets/main.scss
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
@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,5 +1,5 @@
|
|||||||
import { convertFileSrc } from "@tauri-apps/api/core";
|
import { convertFileSrc } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
export const useObject = async (id: string) => {
|
export const useObject = (id: string) => {
|
||||||
return convertFileSrc(id, "object");
|
return convertFileSrc(id, "object");
|
||||||
};
|
};
|
||||||
91
shared/error.vue
Normal file
91
shared/error.vue
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<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>
|
||||||
25
shared/nuxt.config.ts
Normal file
25
shared/nuxt.config.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// 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,
|
||||||
|
},
|
||||||
|
});
|
||||||
37
shared/package.json
Normal file
37
shared/package.json
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
20
shared/tailwind.config.js
Normal file
20
shared/tailwind.config.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/** @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')],
|
||||||
|
};
|
||||||
5
shared/tsconfig.json
Normal file
5
shared/tsconfig.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
// https://nuxt.com/docs/guide/concepts/typescript
|
||||||
|
"extends": "./.nuxt/tsconfig.json",
|
||||||
|
"exclude": ["src-tauri/**/*"]
|
||||||
|
}
|
||||||
96
shared/types.ts
Normal file
96
shared/types.ts
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
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
Normal file
8091
shared/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
2381
src-tauri/Cargo.lock
generated
2381
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -78,6 +78,16 @@ futures-core = "0.3.31"
|
|||||||
bytes = "1.10.1"
|
bytes = "1.10.1"
|
||||||
# tailscale = { path = "./tailscale" }
|
# tailscale = { path = "./tailscale" }
|
||||||
|
|
||||||
|
|
||||||
|
# Workspaces
|
||||||
|
client = { version = "0.1.0", path = "./client" }
|
||||||
|
database = { path = "./database" }
|
||||||
|
process = { path = "./process" }
|
||||||
|
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]
|
[dependencies.dynfmt]
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
features = ["curly"]
|
features = ["curly"]
|
||||||
@ -127,3 +137,18 @@ features = ["derive", "rc"]
|
|||||||
lto = true
|
lto = true
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
panic = 'abort'
|
panic = 'abort'
|
||||||
|
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"client",
|
||||||
|
"database",
|
||||||
|
"process",
|
||||||
|
"remote",
|
||||||
|
"utils",
|
||||||
|
"cloud_saves",
|
||||||
|
"download_manager",
|
||||||
|
"games",
|
||||||
|
]
|
||||||
|
|
||||||
|
resolver = "3"
|
||||||
4862
src-tauri/client/Cargo.lock
generated
Normal file
4862
src-tauri/client/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
src-tauri/client/Cargo.toml
Normal file
12
src-tauri/client/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "client"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bitcode = "0.6.7"
|
||||||
|
database = { version = "0.1.0", path = "../database" }
|
||||||
|
log = "0.4.28"
|
||||||
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
tauri = "2.8.5"
|
||||||
|
tauri-plugin-autostart = "2.5.0"
|
||||||
12
src-tauri/client/src/app_status.rs
Normal file
12
src-tauri/client/src/app_status.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Serialize, Eq, PartialEq)]
|
||||||
|
pub enum AppStatus {
|
||||||
|
NotConfigured,
|
||||||
|
Offline,
|
||||||
|
ServerError,
|
||||||
|
SignedOut,
|
||||||
|
SignedIn,
|
||||||
|
SignedInNeedsReauth,
|
||||||
|
ServerUnavailable,
|
||||||
|
}
|
||||||
26
src-tauri/client/src/autostart.rs
Normal file
26
src-tauri/client/src/autostart.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use database::borrow_db_checked;
|
||||||
|
use log::debug;
|
||||||
|
use tauri::AppHandle;
|
||||||
|
use tauri_plugin_autostart::ManagerExt;
|
||||||
|
|
||||||
|
// New function to sync state on startup
|
||||||
|
pub fn sync_autostart_on_startup(app: &AppHandle) -> Result<(), String> {
|
||||||
|
let db_handle = borrow_db_checked();
|
||||||
|
let should_be_enabled = db_handle.settings.autostart;
|
||||||
|
drop(db_handle);
|
||||||
|
|
||||||
|
let manager = app.autolaunch();
|
||||||
|
let current_state = manager.is_enabled().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
if current_state != should_be_enabled {
|
||||||
|
if should_be_enabled {
|
||||||
|
manager.enable().map_err(|e| e.to_string())?;
|
||||||
|
debug!("synced autostart: enabled");
|
||||||
|
} else {
|
||||||
|
manager.disable().map_err(|e| e.to_string())?;
|
||||||
|
debug!("synced autostart: disabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
52
src-tauri/client/src/compat.rs
Normal file
52
src-tauri/client/src/compat.rs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
use std::{
|
||||||
|
ffi::OsStr,
|
||||||
|
path::PathBuf,
|
||||||
|
process::{Command, Stdio},
|
||||||
|
sync::LazyLock,
|
||||||
|
};
|
||||||
|
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
pub static COMPAT_INFO: LazyLock<Option<CompatInfo>> = LazyLock::new(create_new_compat_info);
|
||||||
|
|
||||||
|
pub static UMU_LAUNCHER_EXECUTABLE: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
|
||||||
|
let x = get_umu_executable();
|
||||||
|
info!("{:?}", &x);
|
||||||
|
x
|
||||||
|
});
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct CompatInfo {
|
||||||
|
pub umu_installed: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_new_compat_info() -> Option<CompatInfo> {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
return None;
|
||||||
|
|
||||||
|
let has_umu_installed = UMU_LAUNCHER_EXECUTABLE.is_some();
|
||||||
|
Some(CompatInfo {
|
||||||
|
umu_installed: has_umu_installed,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const UMU_BASE_LAUNCHER_EXECUTABLE: &str = "umu-run";
|
||||||
|
const UMU_INSTALL_DIRS: [&str; 4] = ["/app/share", "/use/local/share", "/usr/share", "/opt"];
|
||||||
|
|
||||||
|
fn get_umu_executable() -> Option<PathBuf> {
|
||||||
|
if check_executable_exists(UMU_BASE_LAUNCHER_EXECUTABLE) {
|
||||||
|
return Some(PathBuf::from(UMU_BASE_LAUNCHER_EXECUTABLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
for dir in UMU_INSTALL_DIRS {
|
||||||
|
let p = PathBuf::from(dir).join(UMU_BASE_LAUNCHER_EXECUTABLE);
|
||||||
|
if check_executable_exists(&p) {
|
||||||
|
return Some(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
fn check_executable_exists<P: AsRef<OsStr>>(exec: P) -> bool {
|
||||||
|
let has_umu_installed = Command::new(exec).stdout(Stdio::null()).output();
|
||||||
|
has_umu_installed.is_ok()
|
||||||
|
}
|
||||||
4
src-tauri/client/src/lib.rs
Normal file
4
src-tauri/client/src/lib.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
pub mod app_status;
|
||||||
|
pub mod autostart;
|
||||||
|
pub mod compat;
|
||||||
|
pub mod user;
|
||||||
12
src-tauri/client/src/user.rs
Normal file
12
src-tauri/client/src/user.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use bitcode::{Decode, Encode};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize, Deserialize, Encode, Decode)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct User {
|
||||||
|
id: String,
|
||||||
|
username: String,
|
||||||
|
admin: bool,
|
||||||
|
display_name: String,
|
||||||
|
profile_picture_object_id: String,
|
||||||
|
}
|
||||||
19
src-tauri/cloud_saves/Cargo.toml
Normal file
19
src-tauri/cloud_saves/Cargo.toml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
[package]
|
||||||
|
name = "cloud_saves"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
database = { version = "0.1.0", path = "../database" }
|
||||||
|
dirs = "6.0.0"
|
||||||
|
log = "0.4.28"
|
||||||
|
regex = "1.11.3"
|
||||||
|
rustix = "1.1.2"
|
||||||
|
serde = "1.0.228"
|
||||||
|
serde_json = "1.0.145"
|
||||||
|
serde_with = "3.15.0"
|
||||||
|
tar = "0.4.44"
|
||||||
|
tempfile = "3.23.0"
|
||||||
|
uuid = "1.18.1"
|
||||||
|
whoami = "1.6.1"
|
||||||
|
zstd = "0.13.3"
|
||||||
234
src-tauri/cloud_saves/src/backup_manager.rs
Normal file
234
src-tauri/cloud_saves/src/backup_manager.rs
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
use std::{collections::HashMap, path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
use database::platform::Platform;
|
||||||
|
use database::{GameVersion, db::DATA_ROOT_DIR};
|
||||||
|
use log::warn;
|
||||||
|
|
||||||
|
use crate::error::BackupError;
|
||||||
|
|
||||||
|
use super::path::CommonPath;
|
||||||
|
|
||||||
|
pub struct BackupManager<'a> {
|
||||||
|
pub current_platform: Platform,
|
||||||
|
pub sources: HashMap<(Platform, Platform), &'a (dyn BackupHandler + Sync + Send)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for BackupManager<'_> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BackupManager<'_> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
BackupManager {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
current_platform: Platform::Windows,
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
current_platform: Platform::MacOs,
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
current_platform: Platform::Linux,
|
||||||
|
|
||||||
|
sources: HashMap::from([
|
||||||
|
// Current platform to target platform
|
||||||
|
(
|
||||||
|
(Platform::Windows, Platform::Windows),
|
||||||
|
&WindowsBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
(Platform::Linux, Platform::Linux),
|
||||||
|
&LinuxBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
(Platform::MacOs, Platform::MacOs),
|
||||||
|
&MacBackupManager {} as &(dyn BackupHandler + Sync + Send),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait BackupHandler: Send + Sync {
|
||||||
|
fn root_translate(&self, _path: &PathBuf, _game: &GameVersion) -> Result<PathBuf, BackupError> {
|
||||||
|
Ok(DATA_ROOT_DIR.join("games"))
|
||||||
|
}
|
||||||
|
fn game_translate(&self, _path: &PathBuf, game: &GameVersion) -> Result<PathBuf, BackupError> {
|
||||||
|
Ok(PathBuf::from_str(&game.game_id).unwrap())
|
||||||
|
}
|
||||||
|
fn base_translate(&self, path: &PathBuf, game: &GameVersion) -> Result<PathBuf, BackupError> {
|
||||||
|
Ok(self
|
||||||
|
.root_translate(path, game)?
|
||||||
|
.join(self.game_translate(path, game)?))
|
||||||
|
}
|
||||||
|
fn home_translate(&self, _path: &PathBuf, _game: &GameVersion) -> Result<PathBuf, BackupError> {
|
||||||
|
let c = CommonPath::Home.get().ok_or(BackupError::NotFound);
|
||||||
|
println!("{:?}", c);
|
||||||
|
c
|
||||||
|
}
|
||||||
|
fn store_user_id_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
PathBuf::from_str(&game.game_id).map_err(|_| BackupError::ParseError)
|
||||||
|
}
|
||||||
|
fn os_user_name_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
Ok(PathBuf::from_str(&whoami::username()).unwrap())
|
||||||
|
}
|
||||||
|
fn win_app_data_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
warn!("Unexpected Windows Reference in Backup <winAppData>");
|
||||||
|
Err(BackupError::InvalidSystem)
|
||||||
|
}
|
||||||
|
fn win_local_app_data_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
warn!("Unexpected Windows Reference in Backup <winLocalAppData>");
|
||||||
|
Err(BackupError::InvalidSystem)
|
||||||
|
}
|
||||||
|
fn win_local_app_data_low_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
warn!("Unexpected Windows Reference in Backup <winLocalAppDataLow>");
|
||||||
|
Err(BackupError::InvalidSystem)
|
||||||
|
}
|
||||||
|
fn win_documents_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
warn!("Unexpected Windows Reference in Backup <winDocuments>");
|
||||||
|
Err(BackupError::InvalidSystem)
|
||||||
|
}
|
||||||
|
fn win_public_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
warn!("Unexpected Windows Reference in Backup <winPublic>");
|
||||||
|
Err(BackupError::InvalidSystem)
|
||||||
|
}
|
||||||
|
fn win_program_data_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
warn!("Unexpected Windows Reference in Backup <winProgramData>");
|
||||||
|
Err(BackupError::InvalidSystem)
|
||||||
|
}
|
||||||
|
fn win_dir_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
warn!("Unexpected Windows Reference in Backup <winDir>");
|
||||||
|
Err(BackupError::InvalidSystem)
|
||||||
|
}
|
||||||
|
fn xdg_data_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
warn!("Unexpected XDG Reference in Backup <xdgData>");
|
||||||
|
Err(BackupError::InvalidSystem)
|
||||||
|
}
|
||||||
|
fn xdg_config_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
warn!("Unexpected XDG Reference in Backup <xdgConfig>");
|
||||||
|
Err(BackupError::InvalidSystem)
|
||||||
|
}
|
||||||
|
fn skip_translate(&self, _path: &PathBuf, _game: &GameVersion) -> Result<PathBuf, BackupError> {
|
||||||
|
Ok(PathBuf::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct LinuxBackupManager {}
|
||||||
|
impl BackupHandler for LinuxBackupManager {
|
||||||
|
fn xdg_config_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
CommonPath::Data.get().ok_or(BackupError::NotFound)
|
||||||
|
}
|
||||||
|
fn xdg_data_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
CommonPath::Config.get().ok_or(BackupError::NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub struct WindowsBackupManager {}
|
||||||
|
impl BackupHandler for WindowsBackupManager {
|
||||||
|
fn win_app_data_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
CommonPath::Config.get().ok_or(BackupError::NotFound)
|
||||||
|
}
|
||||||
|
fn win_local_app_data_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
CommonPath::DataLocal.get().ok_or(BackupError::NotFound)
|
||||||
|
}
|
||||||
|
fn win_local_app_data_low_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
CommonPath::DataLocalLow
|
||||||
|
.get()
|
||||||
|
.ok_or(BackupError::NotFound)
|
||||||
|
}
|
||||||
|
fn win_dir_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
Ok(PathBuf::from_str("C:/Windows").unwrap())
|
||||||
|
}
|
||||||
|
fn win_documents_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
CommonPath::Document.get().ok_or(BackupError::NotFound)
|
||||||
|
}
|
||||||
|
fn win_program_data_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
Ok(PathBuf::from_str("C:/ProgramData").unwrap())
|
||||||
|
}
|
||||||
|
fn win_public_translate(
|
||||||
|
&self,
|
||||||
|
_path: &PathBuf,
|
||||||
|
_game: &GameVersion,
|
||||||
|
) -> Result<PathBuf, BackupError> {
|
||||||
|
CommonPath::Public.get().ok_or(BackupError::NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub struct MacBackupManager {}
|
||||||
|
impl BackupHandler for MacBackupManager {}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
use crate::process::process_manager::Platform;
|
use database::platform::Platform;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum Condition {
|
pub enum Condition {
|
||||||
Os(Platform)
|
Os(Platform),
|
||||||
|
Other
|
||||||
}
|
}
|
||||||
27
src-tauri/cloud_saves/src/error.rs
Normal file
27
src-tauri/cloud_saves/src/error.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use serde_with::SerializeDisplay;
|
||||||
|
|
||||||
|
#[derive(Debug, SerializeDisplay, Clone, Copy)]
|
||||||
|
|
||||||
|
pub enum BackupError {
|
||||||
|
InvalidSystem,
|
||||||
|
|
||||||
|
NotFound,
|
||||||
|
|
||||||
|
ParseError,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for BackupError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let s = match self {
|
||||||
|
BackupError::InvalidSystem => "Attempted to generate path for invalid system",
|
||||||
|
|
||||||
|
BackupError::NotFound => "Could not generate or find path",
|
||||||
|
|
||||||
|
BackupError::ParseError => "Failed to parse path",
|
||||||
|
};
|
||||||
|
|
||||||
|
write!(f, "{}", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src-tauri/cloud_saves/src/lib.rs
Normal file
8
src-tauri/cloud_saves/src/lib.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
pub mod backup_manager;
|
||||||
|
pub mod conditions;
|
||||||
|
pub mod error;
|
||||||
|
pub mod metadata;
|
||||||
|
pub mod normalise;
|
||||||
|
pub mod path;
|
||||||
|
pub mod placeholder;
|
||||||
|
pub mod resolver;
|
||||||
@ -1,7 +1,6 @@
|
|||||||
use crate::database::db::GameVersion;
|
use database::GameVersion;
|
||||||
|
|
||||||
use super::conditions::{Condition};
|
|
||||||
|
|
||||||
|
use super::conditions::Condition;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct CloudSaveMetadata {
|
pub struct CloudSaveMetadata {
|
||||||
@ -16,15 +15,17 @@ pub struct GameFile {
|
|||||||
pub id: Option<String>,
|
pub id: Option<String>,
|
||||||
pub data_type: DataType,
|
pub data_type: DataType,
|
||||||
pub tags: Vec<Tag>,
|
pub tags: Vec<Tag>,
|
||||||
pub conditions: Vec<Condition>
|
pub conditions: Vec<Condition>,
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum DataType {
|
pub enum DataType {
|
||||||
Registry,
|
Registry,
|
||||||
File,
|
File,
|
||||||
Other
|
Other,
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
|
#[derive(
|
||||||
|
Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
|
||||||
|
)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum Tag {
|
pub enum Tag {
|
||||||
Config,
|
Config,
|
||||||
@ -1,11 +1,10 @@
|
|||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
use database::platform::Platform;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use crate::process::process_manager::Platform;
|
|
||||||
|
|
||||||
use super::placeholder::*;
|
use super::placeholder::*;
|
||||||
|
|
||||||
|
|
||||||
pub fn normalize(path: &str, os: Platform) -> String {
|
pub fn normalize(path: &str, os: Platform) -> String {
|
||||||
let mut path = path.trim().trim_end_matches(['/', '\\']).replace('\\', "/");
|
let mut path = path.trim().trim_end_matches(['/', '\\']).replace('\\', "/");
|
||||||
|
|
||||||
@ -14,18 +13,25 @@ pub fn normalize(path: &str, os: Platform) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CONSECUTIVE_SLASHES: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"/{2,}").unwrap());
|
static CONSECUTIVE_SLASHES: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"/{2,}").unwrap());
|
||||||
static UNNECESSARY_DOUBLE_STAR_1: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"([^/*])\*{2,}").unwrap());
|
static UNNECESSARY_DOUBLE_STAR_1: LazyLock<Regex> =
|
||||||
static UNNECESSARY_DOUBLE_STAR_2: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\*{2,}([^/*])").unwrap());
|
LazyLock::new(|| Regex::new(r"([^/*])\*{2,}").unwrap());
|
||||||
|
static UNNECESSARY_DOUBLE_STAR_2: LazyLock<Regex> =
|
||||||
|
LazyLock::new(|| Regex::new(r"\*{2,}([^/*])").unwrap());
|
||||||
static ENDING_WILDCARD: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(/\*)+$").unwrap());
|
static ENDING_WILDCARD: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(/\*)+$").unwrap());
|
||||||
static ENDING_DOT: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(/\.)$").unwrap());
|
static ENDING_DOT: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(/\.)$").unwrap());
|
||||||
static INTERMEDIATE_DOT: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(/\./)").unwrap());
|
static INTERMEDIATE_DOT: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(/\./)").unwrap());
|
||||||
static BLANK_SEGMENT: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(/\s+/)").unwrap());
|
static BLANK_SEGMENT: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(/\s+/)").unwrap());
|
||||||
static APP_DATA: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)%appdata%").unwrap());
|
static APP_DATA: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)%appdata%").unwrap());
|
||||||
static APP_DATA_ROAMING: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)%userprofile%/AppData/Roaming").unwrap());
|
static APP_DATA_ROAMING: LazyLock<Regex> =
|
||||||
static APP_DATA_LOCAL: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)%localappdata%").unwrap());
|
LazyLock::new(|| Regex::new(r"(?i)%userprofile%/AppData/Roaming").unwrap());
|
||||||
static APP_DATA_LOCAL_2: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)%userprofile%/AppData/Local/").unwrap());
|
static APP_DATA_LOCAL: LazyLock<Regex> =
|
||||||
static USER_PROFILE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)%userprofile%").unwrap());
|
LazyLock::new(|| Regex::new(r"(?i)%localappdata%").unwrap());
|
||||||
static DOCUMENTS: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)%userprofile%/Documents").unwrap());
|
static APP_DATA_LOCAL_2: LazyLock<Regex> =
|
||||||
|
LazyLock::new(|| Regex::new(r"(?i)%userprofile%/AppData/Local/").unwrap());
|
||||||
|
static USER_PROFILE: LazyLock<Regex> =
|
||||||
|
LazyLock::new(|| Regex::new(r"(?i)%userprofile%").unwrap());
|
||||||
|
static DOCUMENTS: LazyLock<Regex> =
|
||||||
|
LazyLock::new(|| Regex::new(r"(?i)%userprofile%/Documents").unwrap());
|
||||||
|
|
||||||
for (pattern, replacement) in [
|
for (pattern, replacement) in [
|
||||||
(&CONSECUTIVE_SLASHES, "/"),
|
(&CONSECUTIVE_SLASHES, "/"),
|
||||||
@ -66,7 +72,9 @@ pub fn normalize(path: &str, os: Platform) -> String {
|
|||||||
|
|
||||||
fn too_broad(path: &str) -> bool {
|
fn too_broad(path: &str) -> bool {
|
||||||
println!("Path: {}", path);
|
println!("Path: {}", path);
|
||||||
use {BASE, HOME, ROOT, STORE_USER_ID, WIN_APP_DATA, WIN_DIR, WIN_DOCUMENTS, XDG_CONFIG, XDG_DATA};
|
use {
|
||||||
|
BASE, HOME, ROOT, STORE_USER_ID, WIN_APP_DATA, WIN_DIR, WIN_DOCUMENTS, XDG_CONFIG, XDG_DATA,
|
||||||
|
};
|
||||||
|
|
||||||
let path_lower = path.to_lowercase();
|
let path_lower = path.to_lowercase();
|
||||||
|
|
||||||
@ -77,7 +85,9 @@ fn too_broad(path: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for item in AVOID_WILDCARDS {
|
for item in AVOID_WILDCARDS {
|
||||||
if path.starts_with(&format!("{}/*", item)) || path.starts_with(&format!("{}/{}", item, STORE_USER_ID)) {
|
if path.starts_with(&format!("{}/*", item))
|
||||||
|
|| path.starts_with(&format!("{}/{}", item, STORE_USER_ID))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +135,6 @@ fn too_broad(path: &str) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Drive letters:
|
// Drive letters:
|
||||||
let drives: Regex = Regex::new(r"^[a-zA-Z]:$").unwrap();
|
let drives: Regex = Regex::new(r"^[a-zA-Z]:$").unwrap();
|
||||||
if drives.is_match(path) {
|
if drives.is_match(path) {
|
||||||
@ -13,12 +13,12 @@ pub enum CommonPath {
|
|||||||
|
|
||||||
impl CommonPath {
|
impl CommonPath {
|
||||||
pub fn get(&self) -> Option<PathBuf> {
|
pub fn get(&self) -> Option<PathBuf> {
|
||||||
static CONFIG: LazyLock<Option<PathBuf>> = LazyLock::new(|| dirs::config_dir());
|
static CONFIG: LazyLock<Option<PathBuf>> = LazyLock::new(dirs::config_dir);
|
||||||
static DATA: LazyLock<Option<PathBuf>> = LazyLock::new(|| dirs::data_dir());
|
static DATA: LazyLock<Option<PathBuf>> = LazyLock::new(dirs::data_dir);
|
||||||
static DATA_LOCAL: LazyLock<Option<PathBuf>> = LazyLock::new(|| dirs::data_local_dir());
|
static DATA_LOCAL: LazyLock<Option<PathBuf>> = LazyLock::new(dirs::data_local_dir);
|
||||||
static DOCUMENT: LazyLock<Option<PathBuf>> = LazyLock::new(|| dirs::document_dir());
|
static DOCUMENT: LazyLock<Option<PathBuf>> = LazyLock::new(dirs::document_dir);
|
||||||
static HOME: LazyLock<Option<PathBuf>> = LazyLock::new(|| dirs::home_dir());
|
static HOME: LazyLock<Option<PathBuf>> = LazyLock::new(dirs::home_dir);
|
||||||
static PUBLIC: LazyLock<Option<PathBuf>> = LazyLock::new(|| dirs::public_dir());
|
static PUBLIC: LazyLock<Option<PathBuf>> = LazyLock::new(dirs::public_dir);
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
static DATA_LOCAL_LOW: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
|
static DATA_LOCAL_LOW: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
|
||||||
@ -48,4 +48,4 @@ pub const XDG_DATA: &str = "<xdgData>"; // %WINDIR% on Windows
|
|||||||
pub const XDG_CONFIG: &str = "<xdgConfig>"; // $XDG_DATA_HOME on Linux
|
pub const XDG_CONFIG: &str = "<xdgConfig>"; // $XDG_DATA_HOME on Linux
|
||||||
pub const SKIP: &str = "<skip>"; // $XDG_CONFIG_HOME on Linux
|
pub const SKIP: &str = "<skip>"; // $XDG_CONFIG_HOME on Linux
|
||||||
|
|
||||||
pub static OS_USERNAME: LazyLock<String> = LazyLock::new(|| whoami::username());
|
pub static OS_USERNAME: LazyLock<String> = LazyLock::new(whoami::username);
|
||||||
@ -1,22 +1,17 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{self, create_dir_all, File},
|
fs::{self, File, create_dir_all},
|
||||||
io::{self, ErrorKind, Read, Write},
|
io::{self, Read, Write},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
thread::sleep,
|
|
||||||
time::Duration,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use crate::error::BackupError;
|
||||||
backup_manager::BackupHandler, conditions::Condition, metadata::GameFile, placeholder::*,
|
|
||||||
};
|
use super::{backup_manager::BackupHandler, placeholder::*};
|
||||||
|
use database::GameVersion;
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use rustix::path::Arg;
|
use rustix::path::Arg;
|
||||||
use tempfile::tempfile;
|
use tempfile::tempfile;
|
||||||
|
|
||||||
use crate::{
|
|
||||||
database::db::GameVersion, error::backup_error::BackupError, process::process_manager::Platform,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{backup_manager::BackupManager, metadata::CloudSaveMetadata, normalise::normalize};
|
use super::{backup_manager::BackupManager, metadata::CloudSaveMetadata, normalise::normalize};
|
||||||
|
|
||||||
pub fn resolve(meta: &mut CloudSaveMetadata) -> File {
|
pub fn resolve(meta: &mut CloudSaveMetadata) -> File {
|
||||||
@ -31,7 +26,7 @@ pub fn resolve(meta: &mut CloudSaveMetadata) -> File {
|
|||||||
.iter()
|
.iter()
|
||||||
.find_map(|p| match p {
|
.find_map(|p| match p {
|
||||||
super::conditions::Condition::Os(os) => Some(os),
|
super::conditions::Condition::Os(os) => Some(os),
|
||||||
_ => None,
|
_ => None
|
||||||
})
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
{
|
{
|
||||||
@ -64,7 +59,7 @@ pub fn resolve(meta: &mut CloudSaveMetadata) -> File {
|
|||||||
let binding = serde_json::to_string(meta).unwrap();
|
let binding = serde_json::to_string(meta).unwrap();
|
||||||
let serialized = binding.as_bytes();
|
let serialized = binding.as_bytes();
|
||||||
let mut file = tempfile().unwrap();
|
let mut file = tempfile().unwrap();
|
||||||
file.write(serialized).unwrap();
|
file.write_all(serialized).unwrap();
|
||||||
tarball.append_file("metadata", &mut file).unwrap();
|
tarball.append_file("metadata", &mut file).unwrap();
|
||||||
tarball.into_inner().unwrap().finish().unwrap()
|
tarball.into_inner().unwrap().finish().unwrap()
|
||||||
}
|
}
|
||||||
@ -97,7 +92,7 @@ pub fn extract(file: PathBuf) -> Result<(), BackupError> {
|
|||||||
.iter()
|
.iter()
|
||||||
.find_map(|p| match p {
|
.find_map(|p| match p {
|
||||||
super::conditions::Condition::Os(os) => Some(os),
|
super::conditions::Condition::Os(os) => Some(os),
|
||||||
_ => None,
|
_ => None
|
||||||
})
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
{
|
{
|
||||||
@ -116,7 +111,7 @@ pub fn extract(file: PathBuf) -> Result<(), BackupError> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let new_path = parse_path(file.path.into(), handler, &manifest.game_version)?;
|
let new_path = parse_path(file.path.into(), handler, &manifest.game_version)?;
|
||||||
create_dir_all(&new_path.parent().unwrap()).unwrap();
|
create_dir_all(new_path.parent().unwrap()).unwrap();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Current path {:?} copying to {:?}",
|
"Current path {:?} copying to {:?}",
|
||||||
@ -133,23 +128,22 @@ pub fn copy_item<P: AsRef<Path>>(src: P, dest: P) -> io::Result<()> {
|
|||||||
let src_path = src.as_ref();
|
let src_path = src.as_ref();
|
||||||
let dest_path = dest.as_ref();
|
let dest_path = dest.as_ref();
|
||||||
|
|
||||||
let metadata = fs::metadata(&src_path)?;
|
let metadata = fs::metadata(src_path)?;
|
||||||
|
|
||||||
if metadata.is_file() {
|
if metadata.is_file() {
|
||||||
// Ensure the parent directory of the destination exists for a file copy
|
// Ensure the parent directory of the destination exists for a file copy
|
||||||
if let Some(parent) = dest_path.parent() {
|
if let Some(parent) = dest_path.parent() {
|
||||||
fs::create_dir_all(parent)?;
|
fs::create_dir_all(parent)?;
|
||||||
}
|
}
|
||||||
fs::copy(&src_path, &dest_path)?;
|
fs::copy(src_path, dest_path)?;
|
||||||
} else if metadata.is_dir() {
|
} else if metadata.is_dir() {
|
||||||
// For directories, we call the recursive helper function.
|
// For directories, we call the recursive helper function.
|
||||||
// The destination for the recursive copy is the `dest_path` itself.
|
// The destination for the recursive copy is the `dest_path` itself.
|
||||||
copy_dir_recursive(&src_path, &dest_path)?;
|
copy_dir_recursive(src_path, dest_path)?;
|
||||||
} else {
|
} else {
|
||||||
// Handle other file types like symlinks if necessary,
|
// Handle other file types like symlinks if necessary,
|
||||||
// for now, return an error or skip.
|
// for now, return an error or skip.
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::other(
|
||||||
io::ErrorKind::Other,
|
|
||||||
format!("Source {:?} is neither a file nor a directory", src_path),
|
format!("Source {:?} is neither a file nor a directory", src_path),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -158,7 +152,7 @@ pub fn copy_item<P: AsRef<Path>>(src: P, dest: P) -> io::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn copy_dir_recursive(src: &Path, dest: &Path) -> io::Result<()> {
|
fn copy_dir_recursive(src: &Path, dest: &Path) -> io::Result<()> {
|
||||||
fs::create_dir_all(&dest)?;
|
fs::create_dir_all(dest)?;
|
||||||
|
|
||||||
for entry in fs::read_dir(src)? {
|
for entry in fs::read_dir(src)? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
@ -220,43 +214,3 @@ pub fn parse_path(
|
|||||||
println!("Final line: {:?}", &s);
|
println!("Final line: {:?}", &s);
|
||||||
Ok(s)
|
Ok(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test() {
|
|
||||||
let mut meta = CloudSaveMetadata {
|
|
||||||
files: vec![
|
|
||||||
GameFile {
|
|
||||||
path: String::from("<home>/favicon.png"),
|
|
||||||
id: None,
|
|
||||||
data_type: super::metadata::DataType::File,
|
|
||||||
tags: Vec::new(),
|
|
||||||
conditions: vec![Condition::Os(Platform::Linux)],
|
|
||||||
},
|
|
||||||
GameFile {
|
|
||||||
path: String::from("<home>/Documents/Pixel Art"),
|
|
||||||
id: None,
|
|
||||||
data_type: super::metadata::DataType::File,
|
|
||||||
tags: Vec::new(),
|
|
||||||
conditions: vec![Condition::Os(Platform::Linux)],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
game_version: GameVersion {
|
|
||||||
game_id: String::new(),
|
|
||||||
version_name: String::new(),
|
|
||||||
platform: Platform::Linux,
|
|
||||||
launch_command: String::new(),
|
|
||||||
launch_args: Vec::new(),
|
|
||||||
launch_command_template: String::new(),
|
|
||||||
setup_command: String::new(),
|
|
||||||
setup_args: Vec::new(),
|
|
||||||
setup_command_template: String::new(),
|
|
||||||
only_setup: true,
|
|
||||||
version_index: 0,
|
|
||||||
delta: false,
|
|
||||||
umu_id_override: None,
|
|
||||||
},
|
|
||||||
save_id: String::from("aaaaaaa"),
|
|
||||||
};
|
|
||||||
//resolve(&mut meta);
|
|
||||||
|
|
||||||
extract("save".into()).unwrap();
|
|
||||||
}
|
|
||||||
0
src-tauri/cloud_saves/src/strict_path.rs
Normal file
0
src-tauri/cloud_saves/src/strict_path.rs
Normal file
15
src-tauri/database/Cargo.toml
Normal file
15
src-tauri/database/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "database"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
chrono = "0.4.42"
|
||||||
|
dirs = "6.0.0"
|
||||||
|
log = "0.4.28"
|
||||||
|
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
|
||||||
|
rustbreak = "2.0.0"
|
||||||
|
serde = "1.0.228"
|
||||||
|
serde_with = "3.15.0"
|
||||||
|
url = "2.5.7"
|
||||||
|
whoami = "1.6.1"
|
||||||
45
src-tauri/database/src/db.rs
Normal file
45
src-tauri/database/src/db.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
use std::{
|
||||||
|
path::PathBuf,
|
||||||
|
sync::{Arc, LazyLock},
|
||||||
|
};
|
||||||
|
|
||||||
|
use rustbreak::{DeSerError, DeSerializer};
|
||||||
|
use serde::{Serialize, de::DeserializeOwned};
|
||||||
|
|
||||||
|
use crate::interface::{DatabaseImpls, DatabaseInterface};
|
||||||
|
|
||||||
|
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(DatabaseInterface::set_up_database);
|
||||||
|
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
static DATA_ROOT_PREFIX: &str = "drop";
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
static DATA_ROOT_PREFIX: &str = "drop-debug";
|
||||||
|
|
||||||
|
pub static DATA_ROOT_DIR: LazyLock<Arc<PathBuf>> = LazyLock::new(|| {
|
||||||
|
Arc::new(
|
||||||
|
dirs::data_dir()
|
||||||
|
.expect("Failed to get data dir")
|
||||||
|
.join(DATA_ROOT_PREFIX),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Custom JSON serializer to support everything we need
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct DropDatabaseSerializer;
|
||||||
|
|
||||||
|
impl<T: native_model::Model + Serialize + DeserializeOwned> DeSerializer<T>
|
||||||
|
for DropDatabaseSerializer
|
||||||
|
{
|
||||||
|
fn serialize(&self, val: &T) -> rustbreak::error::DeSerResult<Vec<u8>> {
|
||||||
|
native_model::encode(val).map_err(|e| DeSerError::Internal(e.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,53 +3,18 @@ use std::{
|
|||||||
mem::ManuallyDrop,
|
mem::ManuallyDrop,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{Arc, LazyLock, RwLockReadGuard, RwLockWriteGuard},
|
sync::{RwLockReadGuard, RwLockWriteGuard},
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use rustbreak::{DeSerError, DeSerializer, PathDatabase, RustbreakError};
|
use rustbreak::{PathDatabase, RustbreakError};
|
||||||
use serde::{Serialize, de::DeserializeOwned};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::DB;
|
use crate::{
|
||||||
|
db::{DATA_ROOT_DIR, DB, DropDatabaseSerializer},
|
||||||
use super::models::data::Database;
|
models::data::Database,
|
||||||
|
};
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
static DATA_ROOT_PREFIX: &'static str = "drop";
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
static DATA_ROOT_PREFIX: &str = "drop-debug";
|
|
||||||
|
|
||||||
pub static DATA_ROOT_DIR: LazyLock<Arc<PathBuf>> = LazyLock::new(|| {
|
|
||||||
Arc::new(
|
|
||||||
dirs::data_dir()
|
|
||||||
.expect("Failed to get data dir")
|
|
||||||
.join(DATA_ROOT_PREFIX),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
// Custom JSON serializer to support everything we need
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct DropDatabaseSerializer;
|
|
||||||
|
|
||||||
impl<T: native_model::Model + Serialize + DeserializeOwned> DeSerializer<T>
|
|
||||||
for DropDatabaseSerializer
|
|
||||||
{
|
|
||||||
fn serialize(&self, val: &T) -> rustbreak::error::DeSerResult<Vec<u8>> {
|
|
||||||
native_model::encode(val)
|
|
||||||
.map_err(|e| DeSerError::Internal(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type DatabaseInterface =
|
pub type DatabaseInterface =
|
||||||
rustbreak::Database<Database, rustbreak::backend::PathBackend, DropDatabaseSerializer>;
|
rustbreak::Database<Database, rustbreak::backend::PathBackend, DropDatabaseSerializer>;
|
||||||
14
src-tauri/database/src/lib.rs
Normal file
14
src-tauri/database/src/lib.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#![feature(nonpoison_rwlock)]
|
||||||
|
|
||||||
|
pub mod db;
|
||||||
|
pub mod debug;
|
||||||
|
pub mod interface;
|
||||||
|
pub mod models;
|
||||||
|
pub mod platform;
|
||||||
|
|
||||||
|
pub use db::DB;
|
||||||
|
pub use interface::{borrow_db_checked, borrow_db_mut_checked};
|
||||||
|
pub use models::data::{
|
||||||
|
ApplicationTransientStatus, Database, DatabaseApplications, DatabaseAuth, DownloadType,
|
||||||
|
DownloadableMetadata, GameDownloadStatus, GameVersion, Settings,
|
||||||
|
};
|
||||||
@ -37,17 +37,18 @@ pub mod data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod v1 {
|
mod v1 {
|
||||||
use crate::process::process_manager::Platform;
|
|
||||||
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 super::{Deserialize, Serialize, native_model};
|
use super::{Deserialize, Serialize, native_model};
|
||||||
|
|
||||||
fn default_template() -> String {
|
fn default_template() -> String {
|
||||||
"{}".to_owned()
|
"{}".to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[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)]
|
#[native_model(id = 2, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)]
|
||||||
pub struct GameVersion {
|
pub struct GameVersion {
|
||||||
@ -190,9 +191,7 @@ pub mod data {
|
|||||||
|
|
||||||
use serde_with::serde_as;
|
use serde_with::serde_as;
|
||||||
|
|
||||||
use super::{
|
use super::{Deserialize, Serialize, native_model, v1};
|
||||||
Deserialize, Serialize, native_model, v1,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::Database)]
|
#[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::Database)]
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||||
@ -281,7 +280,8 @@ pub mod data {
|
|||||||
pub installed_game_version: HashMap<String, v1::DownloadableMetadata>,
|
pub installed_game_version: HashMap<String, v1::DownloadableMetadata>,
|
||||||
|
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub transient_statuses: HashMap<v1::DownloadableMetadata, v1::ApplicationTransientStatus>,
|
pub transient_statuses:
|
||||||
|
HashMap<v1::DownloadableMetadata, v1::ApplicationTransientStatus>,
|
||||||
}
|
}
|
||||||
impl From<v1::DatabaseApplications> for DatabaseApplications {
|
impl From<v1::DatabaseApplications> for DatabaseApplications {
|
||||||
fn from(value: v1::DatabaseApplications) -> Self {
|
fn from(value: v1::DatabaseApplications) -> Self {
|
||||||
@ -302,10 +302,7 @@ pub mod data {
|
|||||||
mod v3 {
|
mod v3 {
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use super::{
|
use super::{Deserialize, Serialize, native_model, v1, v2};
|
||||||
Deserialize, Serialize,
|
|
||||||
native_model, v2, v1,
|
|
||||||
};
|
|
||||||
#[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde, from = v2::Database)]
|
#[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 {
|
||||||
@ -357,6 +354,20 @@ pub mod data {
|
|||||||
compat_info: None,
|
compat_info: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
impl DatabaseAuth {
|
||||||
|
pub fn new(
|
||||||
|
private: String,
|
||||||
|
cert: String,
|
||||||
|
client_id: String,
|
||||||
|
web_token: Option<String>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
private,
|
||||||
|
cert,
|
||||||
|
client_id,
|
||||||
|
web_token,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
46
src-tauri/database/src/platform.rs
Normal file
46
src-tauri/database/src/platform.rs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Eq, Hash, PartialEq, Serialize, Deserialize, Clone, Copy, Debug)]
|
||||||
|
pub enum Platform {
|
||||||
|
Windows,
|
||||||
|
Linux,
|
||||||
|
MacOs,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Platform {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
pub const HOST: Platform = Self::Windows;
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub const HOST: Platform = Self::MacOs;
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub const HOST: Platform = Self::Linux;
|
||||||
|
|
||||||
|
pub fn is_case_sensitive(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Windows | Self::MacOs => false,
|
||||||
|
Self::Linux => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for Platform {
|
||||||
|
fn from(value: &str) -> Self {
|
||||||
|
match value.to_lowercase().trim() {
|
||||||
|
"windows" => Self::Windows,
|
||||||
|
"linux" => Self::Linux,
|
||||||
|
"mac" | "macos" => Self::MacOs,
|
||||||
|
_ => unimplemented!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<whoami::Platform> for Platform {
|
||||||
|
fn from(value: whoami::Platform) -> Self {
|
||||||
|
match value {
|
||||||
|
whoami::Platform::Windows => Platform::Windows,
|
||||||
|
whoami::Platform::Linux => Platform::Linux,
|
||||||
|
whoami::Platform::MacOS => Platform::MacOs,
|
||||||
|
platform => unimplemented!("Playform {} is not supported", platform),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src-tauri/download_manager/Cargo.toml
Normal file
17
src-tauri/download_manager/Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "download_manager"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
atomic-instant-full = "0.1.0"
|
||||||
|
database = { version = "0.1.0", path = "../database" }
|
||||||
|
humansize = "2.1.3"
|
||||||
|
log = "0.4.28"
|
||||||
|
parking_lot = "0.12.5"
|
||||||
|
remote = { version = "0.1.0", path = "../remote" }
|
||||||
|
serde = "1.0.228"
|
||||||
|
serde_with = "3.15.0"
|
||||||
|
tauri = "2.8.5"
|
||||||
|
throttle_my_fn = "0.2.6"
|
||||||
|
utils = { version = "0.1.0", path = "../utils" }
|
||||||
@ -7,11 +7,15 @@ use std::{
|
|||||||
thread::{JoinHandle, spawn},
|
thread::{JoinHandle, spawn},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use database::DownloadableMetadata;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use tauri::{AppHandle, Emitter};
|
use tauri::AppHandle;
|
||||||
|
use utils::{app_emit, lock, send};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app_emit, database::models::data::DownloadableMetadata, download_manager::download_manager_frontend::DownloadStatus, error::application_download_error::ApplicationDownloadError, games::library::{QueueUpdateEvent, QueueUpdateEventQueueData, StatsUpdateEvent}, lock, send
|
download_manager_frontend::DownloadStatus,
|
||||||
|
error::ApplicationDownloadError,
|
||||||
|
frontend_updates::{QueueUpdateEvent, QueueUpdateEventQueueData, StatsUpdateEvent},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@ -288,7 +292,10 @@ impl DownloadManagerBuilder {
|
|||||||
|
|
||||||
if validate_result {
|
if validate_result {
|
||||||
download_agent.on_complete(&app_handle);
|
download_agent.on_complete(&app_handle);
|
||||||
send!(sender, DownloadManagerSignal::Completed(download_agent.metadata()));
|
send!(
|
||||||
|
sender,
|
||||||
|
DownloadManagerSignal::Completed(download_agent.metadata())
|
||||||
|
);
|
||||||
send!(sender, DownloadManagerSignal::UpdateUIQueue);
|
send!(sender, DownloadManagerSignal::UpdateUIQueue);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -369,7 +376,7 @@ impl DownloadManagerBuilder {
|
|||||||
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 };
|
||||||
|
|
||||||
app_emit!(self.app_handle, "update_stats", event_data);
|
app_emit!(&self.app_handle, "update_stats", event_data);
|
||||||
}
|
}
|
||||||
fn push_ui_queue_update(&self) {
|
fn push_ui_queue_update(&self) {
|
||||||
let queue = &self.download_queue.read();
|
let queue = &self.download_queue.read();
|
||||||
@ -388,6 +395,6 @@ impl DownloadManagerBuilder {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let event_data = QueueUpdateEvent { queue: queue_objs };
|
let event_data = QueueUpdateEvent { queue: queue_objs };
|
||||||
app_emit!(self.app_handle, "update_queue", event_data);
|
app_emit!(&self.app_handle, "update_queue", event_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,13 +9,12 @@ use std::{
|
|||||||
thread::JoinHandle,
|
thread::JoinHandle,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use database::DownloadableMetadata;
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use utils::{lock, send};
|
||||||
|
|
||||||
use crate::{
|
use crate::error::ApplicationDownloadError;
|
||||||
database::models::data::DownloadableMetadata,
|
|
||||||
error::application_download_error::ApplicationDownloadError, lock, send,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
download_manager_builder::{CurrentProgressObject, DownloadAgent},
|
download_manager_builder::{CurrentProgressObject, DownloadAgent},
|
||||||
@ -80,6 +79,7 @@ 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<Result<(), ()>>>>,
|
||||||
download_queue: Queue,
|
download_queue: Queue,
|
||||||
@ -124,8 +124,11 @@ impl DownloadManager {
|
|||||||
}
|
}
|
||||||
pub fn rearrange_string(&self, meta: &DownloadableMetadata, new_index: usize) {
|
pub fn rearrange_string(&self, meta: &DownloadableMetadata, new_index: usize) {
|
||||||
let mut queue = self.edit();
|
let mut queue = self.edit();
|
||||||
let current_index = get_index_from_id(&mut queue, meta).expect("Failed to get meta index from id");
|
let current_index =
|
||||||
let to_move = queue.remove(current_index).expect("Failed to remove meta at index from queue");
|
get_index_from_id(&mut queue, meta).expect("Failed to get meta index from id");
|
||||||
|
let to_move = queue
|
||||||
|
.remove(current_index)
|
||||||
|
.expect("Failed to remove meta at index from queue");
|
||||||
queue.insert(new_index, to_move);
|
queue.insert(new_index, to_move);
|
||||||
send!(self.command_sender, DownloadManagerSignal::UpdateUIQueue);
|
send!(self.command_sender, DownloadManagerSignal::UpdateUIQueue);
|
||||||
}
|
}
|
||||||
@ -1,11 +1,9 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use database::DownloadableMetadata;
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
|
|
||||||
use crate::{
|
use crate::error::ApplicationDownloadError;
|
||||||
database::models::data::DownloadableMetadata,
|
|
||||||
error::application_download_error::ApplicationDownloadError,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
download_manager_frontend::DownloadStatus,
|
download_manager_frontend::DownloadStatus,
|
||||||
@ -1,12 +1,36 @@
|
|||||||
|
use humansize::{BINARY, format_size};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{Display, Formatter},
|
fmt::{Display, Formatter},
|
||||||
io, sync::Arc,
|
io,
|
||||||
|
sync::{Arc, mpsc::SendError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use remote::error::RemoteAccessError;
|
||||||
use serde_with::SerializeDisplay;
|
use serde_with::SerializeDisplay;
|
||||||
use humansize::{format_size, BINARY};
|
|
||||||
|
|
||||||
use super::remote_access_error::RemoteAccessError;
|
#[derive(SerializeDisplay)]
|
||||||
|
pub enum DownloadManagerError<T> {
|
||||||
|
IOError(io::Error),
|
||||||
|
SignalError(SendError<T>),
|
||||||
|
}
|
||||||
|
impl<T> Display for DownloadManagerError<T> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
DownloadManagerError::IOError(error) => write!(f, "{error}"),
|
||||||
|
DownloadManagerError::SignalError(send_error) => write!(f, "{send_error}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T> From<SendError<T>> for DownloadManagerError<T> {
|
||||||
|
fn from(value: SendError<T>) -> Self {
|
||||||
|
DownloadManagerError::SignalError(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T> From<io::Error> for DownloadManagerError<T> {
|
||||||
|
fn from(value: io::Error) -> Self {
|
||||||
|
DownloadManagerError::IOError(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Rename / separate from downloads
|
// TODO: Rename / separate from downloads
|
||||||
#[derive(Debug, SerializeDisplay)]
|
#[derive(Debug, SerializeDisplay)]
|
||||||
@ -24,7 +48,9 @@ pub enum ApplicationDownloadError {
|
|||||||
impl Display for ApplicationDownloadError {
|
impl Display for ApplicationDownloadError {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ApplicationDownloadError::NotInitialized => write!(f, "Download not initalized, did something go wrong?"),
|
ApplicationDownloadError::NotInitialized => {
|
||||||
|
write!(f, "Download not initalized, did something go wrong?")
|
||||||
|
}
|
||||||
ApplicationDownloadError::DiskFull(required, available) => write!(
|
ApplicationDownloadError::DiskFull(required, available) => write!(
|
||||||
f,
|
f,
|
||||||
"Game requires {}, {} remaining left on disk.",
|
"Game requires {}, {} remaining left on disk.",
|
||||||
@ -40,10 +66,9 @@ impl Display for ApplicationDownloadError {
|
|||||||
write!(f, "checksum failed to validate for download")
|
write!(f, "checksum failed to validate for download")
|
||||||
}
|
}
|
||||||
ApplicationDownloadError::IoError(error) => write!(f, "io error: {error}"),
|
ApplicationDownloadError::IoError(error) => write!(f, "io error: {error}"),
|
||||||
ApplicationDownloadError::DownloadError(error) => write!(
|
ApplicationDownloadError::DownloadError(error) => {
|
||||||
f,
|
write!(f, "Download failed with error {error:?}")
|
||||||
"Download failed with error {error:?}"
|
}
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
24
src-tauri/download_manager/src/frontend_updates.rs
Normal file
24
src-tauri/download_manager/src/frontend_updates.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use database::DownloadableMetadata;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::download_manager_frontend::DownloadStatus;
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone)]
|
||||||
|
pub struct QueueUpdateEventQueueData {
|
||||||
|
pub meta: DownloadableMetadata,
|
||||||
|
pub status: DownloadStatus,
|
||||||
|
pub progress: f64,
|
||||||
|
pub current: usize,
|
||||||
|
pub max: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone)]
|
||||||
|
pub struct QueueUpdateEvent {
|
||||||
|
pub queue: Vec<QueueUpdateEventQueueData>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone)]
|
||||||
|
pub struct StatsUpdateEvent {
|
||||||
|
pub speed: usize,
|
||||||
|
pub time: usize,
|
||||||
|
}
|
||||||
44
src-tauri/download_manager/src/lib.rs
Normal file
44
src-tauri/download_manager/src/lib.rs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#![feature(duration_millis_float)]
|
||||||
|
#![feature(nonpoison_mutex)]
|
||||||
|
#![feature(sync_nonpoison)]
|
||||||
|
|
||||||
|
use std::{ops::Deref, sync::OnceLock};
|
||||||
|
|
||||||
|
use tauri::AppHandle;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
download_manager_builder::DownloadManagerBuilder, download_manager_frontend::DownloadManager,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub mod download_manager_builder;
|
||||||
|
pub mod download_manager_frontend;
|
||||||
|
pub mod downloadable;
|
||||||
|
pub mod error;
|
||||||
|
pub mod frontend_updates;
|
||||||
|
pub mod util;
|
||||||
|
|
||||||
|
pub static DOWNLOAD_MANAGER: DownloadManagerWrapper = DownloadManagerWrapper::new();
|
||||||
|
|
||||||
|
pub struct DownloadManagerWrapper(OnceLock<DownloadManager>);
|
||||||
|
impl DownloadManagerWrapper {
|
||||||
|
const fn new() -> Self {
|
||||||
|
DownloadManagerWrapper(OnceLock::new())
|
||||||
|
}
|
||||||
|
pub fn init(app_handle: AppHandle) {
|
||||||
|
DOWNLOAD_MANAGER
|
||||||
|
.0
|
||||||
|
.set(DownloadManagerBuilder::build(app_handle))
|
||||||
|
.expect("Failed to initialise download manager");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for DownloadManagerWrapper {
|
||||||
|
type Target = DownloadManager;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
match self.0.get() {
|
||||||
|
Some(download_manager) => download_manager,
|
||||||
|
None => unreachable!("Download manager should always be initialised"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
|
||||||
Arc,
|
Arc,
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||||
@ -22,7 +22,11 @@ impl From<DownloadThreadControlFlag> for bool {
|
|||||||
/// false => Stop
|
/// false => Stop
|
||||||
impl From<bool> for DownloadThreadControlFlag {
|
impl From<bool> for DownloadThreadControlFlag {
|
||||||
fn from(value: bool) -> Self {
|
fn from(value: bool) -> Self {
|
||||||
if value { DownloadThreadControlFlag::Go } else { DownloadThreadControlFlag::Stop }
|
if value {
|
||||||
|
DownloadThreadControlFlag::Go
|
||||||
|
} else {
|
||||||
|
DownloadThreadControlFlag::Stop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9,12 +9,13 @@ use std::{
|
|||||||
|
|
||||||
use atomic_instant_full::AtomicInstant;
|
use atomic_instant_full::AtomicInstant;
|
||||||
use throttle_my_fn::throttle;
|
use throttle_my_fn::throttle;
|
||||||
|
use utils::{lock, send};
|
||||||
|
|
||||||
use crate::{download_manager::download_manager_frontend::DownloadManagerSignal, lock, send};
|
use crate::download_manager_frontend::DownloadManagerSignal;
|
||||||
|
|
||||||
use super::rolling_progress_updates::RollingProgressWindow;
|
use super::rolling_progress_updates::RollingProgressWindow;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ProgressObject {
|
pub struct ProgressObject {
|
||||||
max: Arc<Mutex<usize>>,
|
max: Arc<Mutex<usize>>,
|
||||||
progress_instances: Arc<Mutex<Vec<Arc<AtomicUsize>>>>,
|
progress_instances: Arc<Mutex<Vec<Arc<AtomicUsize>>>>,
|
||||||
@ -116,7 +117,9 @@ 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);
|
.swap(Instant::now(), Ordering::SeqCst);
|
||||||
let time_since_last_update = Instant::now().duration_since(last_update_time).as_millis_f64();
|
let time_since_last_update = Instant::now()
|
||||||
|
.duration_since(last_update_time)
|
||||||
|
.as_millis_f64();
|
||||||
|
|
||||||
let current_bytes_downloaded = progress.sum();
|
let current_bytes_downloaded = progress.sum();
|
||||||
let max = progress.get_max();
|
let max = progress.get_max();
|
||||||
@ -124,7 +127,8 @@ pub fn calculate_update(progress: &ProgressObject) {
|
|||||||
.bytes_last_update
|
.bytes_last_update
|
||||||
.swap(current_bytes_downloaded, Ordering::Acquire);
|
.swap(current_bytes_downloaded, Ordering::Acquire);
|
||||||
|
|
||||||
let bytes_since_last_update = current_bytes_downloaded.saturating_sub(bytes_at_last_update) as f64;
|
let bytes_since_last_update =
|
||||||
|
current_bytes_downloaded.saturating_sub(bytes_at_last_update) as f64;
|
||||||
|
|
||||||
let kilobytes_per_second = bytes_since_last_update / time_since_last_update;
|
let kilobytes_per_second = bytes_since_last_update / time_since_last_update;
|
||||||
|
|
||||||
@ -3,9 +3,10 @@ use std::{
|
|||||||
sync::{Arc, Mutex, MutexGuard},
|
sync::{Arc, Mutex, MutexGuard},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{database::models::data::DownloadableMetadata, lock};
|
use database::DownloadableMetadata;
|
||||||
|
use utils::lock;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Queue {
|
pub struct Queue {
|
||||||
inner: Arc<Mutex<VecDeque<DownloadableMetadata>>>,
|
inner: Arc<Mutex<VecDeque<DownloadableMetadata>>>,
|
||||||
}
|
}
|
||||||
@ -3,11 +3,17 @@ use std::sync::{
|
|||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RollingProgressWindow<const S: usize> {
|
pub struct RollingProgressWindow<const S: usize> {
|
||||||
window: Arc<[AtomicUsize; S]>,
|
window: Arc<[AtomicUsize; S]>,
|
||||||
current: Arc<AtomicUsize>,
|
current: Arc<AtomicUsize>,
|
||||||
}
|
}
|
||||||
|
impl<const S: usize> Default for RollingProgressWindow<S> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<const S: usize> RollingProgressWindow<S> {
|
impl<const S: usize> RollingProgressWindow<S> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
26
src-tauri/games/Cargo.toml
Normal file
26
src-tauri/games/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
[package]
|
||||||
|
name = "games"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
atomic-instant-full = "0.1.0"
|
||||||
|
bitcode = "0.6.7"
|
||||||
|
boxcar = "0.2.14"
|
||||||
|
database = { version = "0.1.0", path = "../database" }
|
||||||
|
download_manager = { version = "0.1.0", path = "../download_manager" }
|
||||||
|
hex = "0.4.3"
|
||||||
|
log = "0.4.28"
|
||||||
|
md5 = "0.8.0"
|
||||||
|
rayon = "1.11.0"
|
||||||
|
remote = { version = "0.1.0", path = "../remote" }
|
||||||
|
reqwest = "0.12.23"
|
||||||
|
rustix = "1.1.2"
|
||||||
|
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"
|
||||||
@ -1,7 +1,7 @@
|
|||||||
use bitcode::{Decode, Encode};
|
use bitcode::{Decode, Encode};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::games::library::Game;
|
use crate::library::Game;
|
||||||
|
|
||||||
pub type Collections = Vec<Collection>;
|
pub type Collections = Vec<Collection>;
|
||||||
|
|
||||||
@ -1,2 +1 @@
|
|||||||
pub mod collection;
|
pub mod collection;
|
||||||
pub mod commands;
|
|
||||||
@ -1,28 +1,20 @@
|
|||||||
use crate::auth::generate_authorization_header;
|
use database::{
|
||||||
use crate::database::db::{borrow_db_checked, borrow_db_mut_checked};
|
ApplicationTransientStatus, DownloadType, DownloadableMetadata, borrow_db_checked,
|
||||||
use crate::database::models::data::{
|
borrow_db_mut_checked,
|
||||||
ApplicationTransientStatus, DownloadType, DownloadableMetadata,
|
|
||||||
};
|
};
|
||||||
use crate::download_manager::download_manager_frontend::{DownloadManagerSignal, DownloadStatus};
|
use download_manager::download_manager_frontend::{DownloadManagerSignal, DownloadStatus};
|
||||||
use crate::download_manager::downloadable::Downloadable;
|
use download_manager::downloadable::Downloadable;
|
||||||
use crate::download_manager::util::download_thread_control_flag::{
|
use download_manager::error::ApplicationDownloadError;
|
||||||
|
use download_manager::util::download_thread_control_flag::{
|
||||||
DownloadThreadControl, DownloadThreadControlFlag,
|
DownloadThreadControl, DownloadThreadControlFlag,
|
||||||
};
|
};
|
||||||
use crate::download_manager::util::progress_object::{ProgressHandle, ProgressObject};
|
use download_manager::util::progress_object::{ProgressHandle, ProgressObject};
|
||||||
use crate::error::application_download_error::ApplicationDownloadError;
|
|
||||||
use crate::error::remote_access_error::RemoteAccessError;
|
|
||||||
use crate::games::downloads::manifest::{
|
|
||||||
DownloadBucket, DownloadContext, DownloadDrop, DropManifest, DropValidateContext, ManifestBody,
|
|
||||||
};
|
|
||||||
use crate::games::downloads::validate::validate_game_chunk;
|
|
||||||
use crate::games::library::{on_game_complete, push_game_update, set_partially_installed};
|
|
||||||
use crate::games::state::GameStatusManager;
|
|
||||||
use crate::process::utils::get_disk_available;
|
|
||||||
use crate::remote::requests::generate_url;
|
|
||||||
use crate::remote::utils::{DROP_CLIENT_ASYNC, DROP_CLIENT_SYNC};
|
|
||||||
use crate::{app_emit, lock, send};
|
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use rayon::ThreadPoolBuilder;
|
use rayon::ThreadPoolBuilder;
|
||||||
|
use remote::auth::generate_authorization_header;
|
||||||
|
use remote::error::RemoteAccessError;
|
||||||
|
use remote::requests::generate_url;
|
||||||
|
use remote::utils::{DROP_CLIENT_ASYNC, DROP_CLIENT_SYNC};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fs::{OpenOptions, create_dir_all};
|
use std::fs::{OpenOptions, create_dir_all};
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -30,11 +22,20 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::sync::mpsc::Sender;
|
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, Emitter};
|
use tauri::AppHandle;
|
||||||
|
use utils::{app_emit, lock, send};
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
use rustix::fs::{FallocateFlags, fallocate};
|
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::validate::validate_game_chunk;
|
||||||
|
use crate::library::{on_game_complete, push_game_update, set_partially_installed};
|
||||||
|
use crate::state::GameStatusManager;
|
||||||
|
|
||||||
use super::download_logic::download_game_bucket;
|
use super::download_logic::download_game_bucket;
|
||||||
use super::drop_data::DropData;
|
use super::drop_data::DropData;
|
||||||
|
|
||||||
@ -103,8 +104,7 @@ impl GameDownloadAgent {
|
|||||||
|
|
||||||
result.ensure_manifest_exists().await?;
|
result.ensure_manifest_exists().await?;
|
||||||
|
|
||||||
let required_space = lock!(result
|
let required_space = lock!(result.manifest)
|
||||||
.manifest)
|
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.values()
|
.values()
|
||||||
@ -453,9 +453,13 @@ impl GameDownloadAgent {
|
|||||||
|
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
||||||
let download_context = download_contexts
|
let download_context =
|
||||||
.get(&bucket.version)
|
download_contexts.get(&bucket.version).unwrap_or_else(|| {
|
||||||
.unwrap_or_else(|| panic!("Could not get bucket version {}. Corrupted state.", bucket.version));
|
panic!(
|
||||||
|
"Could not get bucket version {}. Corrupted state.",
|
||||||
|
bucket.version
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
scope.spawn(move |_| {
|
scope.spawn(move |_| {
|
||||||
// 3 attempts
|
// 3 attempts
|
||||||
@ -693,7 +697,10 @@ impl Downloadable for GameDownloadAgent {
|
|||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("could not mark game as complete: {e}");
|
error!("could not mark game as complete: {e}");
|
||||||
send!(self.sender, DownloadManagerSignal::Error(ApplicationDownloadError::DownloadError(e)));
|
send!(
|
||||||
|
self.sender,
|
||||||
|
DownloadManagerSignal::Error(ApplicationDownloadError::DownloadError(e))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,18 +1,3 @@
|
|||||||
use crate::download_manager::util::download_thread_control_flag::{
|
|
||||||
DownloadThreadControl, DownloadThreadControlFlag,
|
|
||||||
};
|
|
||||||
use crate::download_manager::util::progress_object::ProgressHandle;
|
|
||||||
use crate::error::application_download_error::ApplicationDownloadError;
|
|
||||||
use crate::error::drop_server_error::DropServerError;
|
|
||||||
use crate::error::remote_access_error::RemoteAccessError;
|
|
||||||
use crate::games::downloads::manifest::{ChunkBody, DownloadBucket, DownloadContext, DownloadDrop};
|
|
||||||
use crate::remote::auth::generate_authorization_header;
|
|
||||||
use crate::remote::requests::generate_url;
|
|
||||||
use crate::remote::utils::DROP_CLIENT_SYNC;
|
|
||||||
use log::{debug, info, warn};
|
|
||||||
use md5::{Context, Digest};
|
|
||||||
use reqwest::blocking::Response;
|
|
||||||
|
|
||||||
use std::fs::{Permissions, set_permissions};
|
use std::fs::{Permissions, set_permissions};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@ -25,6 +10,21 @@ use std::{
|
|||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use download_manager::error::ApplicationDownloadError;
|
||||||
|
use download_manager::util::download_thread_control_flag::{
|
||||||
|
DownloadThreadControl, DownloadThreadControlFlag,
|
||||||
|
};
|
||||||
|
use download_manager::util::progress_object::ProgressHandle;
|
||||||
|
use log::{debug, info, warn};
|
||||||
|
use md5::{Context, Digest};
|
||||||
|
use remote::auth::generate_authorization_header;
|
||||||
|
use remote::error::{DropServerError, RemoteAccessError};
|
||||||
|
use remote::requests::generate_url;
|
||||||
|
use remote::utils::DROP_CLIENT_SYNC;
|
||||||
|
use reqwest::blocking::Response;
|
||||||
|
|
||||||
|
use crate::downloads::manifest::{ChunkBody, DownloadBucket, DownloadContext, DownloadDrop};
|
||||||
|
|
||||||
static MAX_PACKET_LENGTH: usize = 4096 * 4;
|
static MAX_PACKET_LENGTH: usize = 4096 * 4;
|
||||||
static BUMP_SIZE: usize = 4096 * 16;
|
static BUMP_SIZE: usize = 4096 * 16;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ impl DropWriter<File> {
|
|||||||
|
|
||||||
fn finish(mut self) -> io::Result<Digest> {
|
fn finish(mut self) -> io::Result<Digest> {
|
||||||
self.flush()?;
|
self.flush()?;
|
||||||
Ok(self.hasher.compute())
|
Ok(self.hasher.finalize())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Write automatically pushes to file and hasher
|
// Write automatically pushes to file and hasher
|
||||||
@ -118,7 +118,10 @@ impl<'a> DropDownloadPipeline<'a, Response, File> {
|
|||||||
let mut last_bump = 0;
|
let mut last_bump = 0;
|
||||||
loop {
|
loop {
|
||||||
let size = MAX_PACKET_LENGTH.min(remaining);
|
let size = MAX_PACKET_LENGTH.min(remaining);
|
||||||
let size = self.source.read(&mut copy_buffer[0..size]).inspect_err(|_| {
|
let size = self
|
||||||
|
.source
|
||||||
|
.read(&mut copy_buffer[0..size])
|
||||||
|
.inspect_err(|_| {
|
||||||
info!("got error from {}", drop.filename);
|
info!("got error from {}", drop.filename);
|
||||||
})?;
|
})?;
|
||||||
remaining -= size;
|
remaining -= size;
|
||||||
@ -1,11 +1,13 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap, fs::File, io::{self, Read, Write}, path::{Path, PathBuf}
|
collections::HashMap,
|
||||||
|
fs::File,
|
||||||
|
io::{self, Read, Write},
|
||||||
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use native_model::{Decode, Encode};
|
use native_model::{Decode, Encode};
|
||||||
|
use utils::lock;
|
||||||
use crate::lock;
|
|
||||||
|
|
||||||
pub type DropData = v1::DropData;
|
pub type DropData = v1::DropData;
|
||||||
|
|
||||||
@ -78,7 +80,10 @@ impl DropData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_contexts(&self, completed_contexts: &[(String, bool)]) {
|
pub fn set_contexts(&self, completed_contexts: &[(String, bool)]) {
|
||||||
*lock!(self.contexts) = completed_contexts.iter().map(|s| (s.0.clone(), s.1)).collect();
|
*lock!(self.contexts) = completed_contexts
|
||||||
|
.iter()
|
||||||
|
.map(|s| (s.0.clone(), s.1))
|
||||||
|
.collect();
|
||||||
}
|
}
|
||||||
pub fn set_context(&self, context: String, state: bool) {
|
pub fn set_context(&self, context: String, state: bool) {
|
||||||
lock!(self.contexts).entry(context).insert_entry(state);
|
lock!(self.contexts).entry(context).insert_entry(state);
|
||||||
29
src-tauri/games/src/downloads/error.rs
Normal file
29
src-tauri/games/src/downloads/error.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use serde_with::SerializeDisplay;
|
||||||
|
|
||||||
|
#[derive(SerializeDisplay)]
|
||||||
|
pub enum LibraryError {
|
||||||
|
MetaNotFound(String),
|
||||||
|
VersionNotFound(String),
|
||||||
|
}
|
||||||
|
impl Display for LibraryError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{}",
|
||||||
|
match self {
|
||||||
|
LibraryError::MetaNotFound(id) => {
|
||||||
|
format!(
|
||||||
|
"Could not locate any installed version of game ID {id} in the database"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
LibraryError::VersionNotFound(game_id) => {
|
||||||
|
format!(
|
||||||
|
"Could not locate any installed version for game id {game_id} in the database"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
pub mod commands;
|
|
||||||
pub mod download_agent;
|
pub mod download_agent;
|
||||||
mod download_logic;
|
mod download_logic;
|
||||||
pub mod drop_data;
|
pub mod drop_data;
|
||||||
|
pub mod error;
|
||||||
mod manifest;
|
mod manifest;
|
||||||
|
pub mod utils;
|
||||||
pub mod validate;
|
pub mod validate;
|
||||||
@ -1,10 +1,8 @@
|
|||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{io, path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
use futures_lite::io;
|
use download_manager::error::ApplicationDownloadError;
|
||||||
use sysinfo::{Disk, DiskRefreshKind, Disks};
|
use sysinfo::{Disk, DiskRefreshKind, Disks};
|
||||||
|
|
||||||
use crate::error::application_download_error::ApplicationDownloadError;
|
|
||||||
|
|
||||||
pub fn get_disk_available(mount_point: PathBuf) -> Result<u64, ApplicationDownloadError> {
|
pub fn get_disk_available(mount_point: PathBuf) -> Result<u64, ApplicationDownloadError> {
|
||||||
let disks = Disks::new_with_refreshed_list_specifics(DiskRefreshKind::nothing().with_storage());
|
let disks = Disks::new_with_refreshed_list_specifics(DiskRefreshKind::nothing().with_storage());
|
||||||
|
|
||||||
@ -21,7 +19,7 @@ pub fn get_disk_available(mount_point: PathBuf) -> Result<u64, ApplicationDownlo
|
|||||||
return Ok(disk.available_space());
|
return Ok(disk.available_space());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ApplicationDownloadError::IoError(Arc::new(io::Error::other(
|
Err(ApplicationDownloadError::IoError(Arc::new(
|
||||||
"could not find disk of path",
|
io::Error::other("could not find disk of path"),
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
@ -3,17 +3,17 @@ use std::{
|
|||||||
io::{self, BufWriter, Read, Seek, SeekFrom, Write},
|
io::{self, BufWriter, Read, Seek, SeekFrom, Write},
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::debug;
|
use download_manager::{
|
||||||
use md5::Context;
|
error::ApplicationDownloadError,
|
||||||
|
util::{
|
||||||
use crate::{
|
|
||||||
download_manager::util::{
|
|
||||||
download_thread_control_flag::{DownloadThreadControl, DownloadThreadControlFlag},
|
download_thread_control_flag::{DownloadThreadControl, DownloadThreadControlFlag},
|
||||||
progress_object::ProgressHandle,
|
progress_object::ProgressHandle,
|
||||||
},
|
},
|
||||||
error::application_download_error::ApplicationDownloadError,
|
|
||||||
games::downloads::manifest::DropValidateContext,
|
|
||||||
};
|
};
|
||||||
|
use log::debug;
|
||||||
|
use md5::Context;
|
||||||
|
|
||||||
|
use crate::downloads::manifest::DropValidateContext;
|
||||||
|
|
||||||
pub fn validate_game_chunk(
|
pub fn validate_game_chunk(
|
||||||
ctx: &DropValidateContext,
|
ctx: &DropValidateContext,
|
||||||
@ -22,7 +22,10 @@ pub fn validate_game_chunk(
|
|||||||
) -> Result<bool, ApplicationDownloadError> {
|
) -> Result<bool, ApplicationDownloadError> {
|
||||||
debug!(
|
debug!(
|
||||||
"Starting chunk validation {}, {}, {} #{}",
|
"Starting chunk validation {}, {}, {} #{}",
|
||||||
ctx.path.display(), ctx.index, ctx.offset, ctx.checksum
|
ctx.path.display(),
|
||||||
|
ctx.index,
|
||||||
|
ctx.offset,
|
||||||
|
ctx.checksum
|
||||||
);
|
);
|
||||||
// If we're paused
|
// If we're paused
|
||||||
if control_flag.get() == DownloadThreadControlFlag::Stop {
|
if control_flag.get() == DownloadThreadControlFlag::Stop {
|
||||||
@ -42,13 +45,12 @@ pub fn validate_game_chunk(
|
|||||||
|
|
||||||
let mut hasher = md5::Context::new();
|
let mut hasher = md5::Context::new();
|
||||||
|
|
||||||
let completed =
|
let completed = validate_copy(&mut source, &mut hasher, ctx.length, control_flag, progress)?;
|
||||||
validate_copy(&mut source, &mut hasher, ctx.length, control_flag, progress)?;
|
|
||||||
if !completed {
|
if !completed {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = hex::encode(hasher.compute().0);
|
let res = hex::encode(hasher.finalize().0);
|
||||||
if res != ctx.checksum {
|
if res != ctx.checksum {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
|
#![feature(iterator_try_collect)]
|
||||||
|
|
||||||
pub mod collections;
|
pub mod collections;
|
||||||
pub mod commands;
|
|
||||||
pub mod downloads;
|
pub mod downloads;
|
||||||
pub mod library;
|
pub mod library;
|
||||||
|
pub mod scan;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
300
src-tauri/games/src/library.rs
Normal file
300
src-tauri/games/src/library.rs
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
use bitcode::{Decode, Encode};
|
||||||
|
use database::{
|
||||||
|
ApplicationTransientStatus, Database, DownloadableMetadata, GameDownloadStatus, GameVersion,
|
||||||
|
borrow_db_checked, borrow_db_mut_checked,
|
||||||
|
};
|
||||||
|
use log::{debug, error, warn};
|
||||||
|
use remote::{
|
||||||
|
auth::generate_authorization_header, error::RemoteAccessError, requests::generate_url,
|
||||||
|
utils::DROP_CLIENT_SYNC,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fs::remove_dir_all;
|
||||||
|
use std::thread::spawn;
|
||||||
|
use tauri::AppHandle;
|
||||||
|
use utils::app_emit;
|
||||||
|
|
||||||
|
use crate::state::{GameStatusManager, GameStatusWithTransient};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct FetchGameStruct {
|
||||||
|
game: Game,
|
||||||
|
status: GameStatusWithTransient,
|
||||||
|
version: Option<GameVersion>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FetchGameStruct {
|
||||||
|
pub fn new(game: Game, status: GameStatusWithTransient, version: Option<GameVersion>) -> Self {
|
||||||
|
Self {
|
||||||
|
game,
|
||||||
|
status,
|
||||||
|
version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug, Default, Encode, Decode)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Game {
|
||||||
|
id: String,
|
||||||
|
m_name: String,
|
||||||
|
m_short_description: String,
|
||||||
|
m_description: String,
|
||||||
|
// mDevelopers
|
||||||
|
// mPublishers
|
||||||
|
m_icon_object_id: String,
|
||||||
|
m_banner_object_id: String,
|
||||||
|
m_cover_object_id: String,
|
||||||
|
m_image_library_object_ids: Vec<String>,
|
||||||
|
m_image_carousel_object_ids: Vec<String>,
|
||||||
|
}
|
||||||
|
impl Game {
|
||||||
|
pub fn id(&self) -> &String {
|
||||||
|
&self.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(serde::Serialize, Clone)]
|
||||||
|
pub struct GameUpdateEvent {
|
||||||
|
pub game_id: String,
|
||||||
|
pub status: (
|
||||||
|
Option<GameDownloadStatus>,
|
||||||
|
Option<ApplicationTransientStatus>,
|
||||||
|
),
|
||||||
|
pub version: Option<GameVersion>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by:
|
||||||
|
* - on_cancel, when cancelled, for obvious reasons
|
||||||
|
* - when downloading, so if drop unexpectedly quits, we can resume the download. hidden by the "Downloading..." transient state, though
|
||||||
|
* - when scanning, to import the game
|
||||||
|
*/
|
||||||
|
pub fn set_partially_installed(
|
||||||
|
meta: &DownloadableMetadata,
|
||||||
|
install_dir: String,
|
||||||
|
app_handle: Option<&AppHandle>,
|
||||||
|
) {
|
||||||
|
set_partially_installed_db(&mut borrow_db_mut_checked(), meta, install_dir, app_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_partially_installed_db(
|
||||||
|
db_lock: &mut Database,
|
||||||
|
meta: &DownloadableMetadata,
|
||||||
|
install_dir: String,
|
||||||
|
app_handle: Option<&AppHandle>,
|
||||||
|
) {
|
||||||
|
db_lock.applications.transient_statuses.remove(meta);
|
||||||
|
db_lock.applications.game_statuses.insert(
|
||||||
|
meta.id.clone(),
|
||||||
|
GameDownloadStatus::PartiallyInstalled {
|
||||||
|
version_name: meta.version.as_ref().unwrap().clone(),
|
||||||
|
install_dir,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
db_lock
|
||||||
|
.applications
|
||||||
|
.installed_game_version
|
||||||
|
.insert(meta.id.clone(), meta.clone());
|
||||||
|
|
||||||
|
if let Some(app_handle) = app_handle {
|
||||||
|
push_game_update(
|
||||||
|
app_handle,
|
||||||
|
&meta.id,
|
||||||
|
None,
|
||||||
|
GameStatusManager::fetch_state(&meta.id, db_lock),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle) {
|
||||||
|
debug!("triggered uninstall for agent");
|
||||||
|
let mut db_handle = borrow_db_mut_checked();
|
||||||
|
db_handle
|
||||||
|
.applications
|
||||||
|
.transient_statuses
|
||||||
|
.insert(meta.clone(), ApplicationTransientStatus::Uninstalling {});
|
||||||
|
|
||||||
|
push_game_update(
|
||||||
|
app_handle,
|
||||||
|
&meta.id,
|
||||||
|
None,
|
||||||
|
GameStatusManager::fetch_state(&meta.id, &db_handle),
|
||||||
|
);
|
||||||
|
|
||||||
|
let previous_state = db_handle.applications.game_statuses.get(&meta.id).cloned();
|
||||||
|
|
||||||
|
let previous_state = if let Some(state) = previous_state {
|
||||||
|
state
|
||||||
|
} else {
|
||||||
|
warn!("uninstall job doesn't have previous state, failing silently");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some((_, install_dir)) = match previous_state {
|
||||||
|
GameDownloadStatus::Installed {
|
||||||
|
version_name,
|
||||||
|
install_dir,
|
||||||
|
} => Some((version_name, install_dir)),
|
||||||
|
GameDownloadStatus::SetupRequired {
|
||||||
|
version_name,
|
||||||
|
install_dir,
|
||||||
|
} => Some((version_name, install_dir)),
|
||||||
|
GameDownloadStatus::PartiallyInstalled {
|
||||||
|
version_name,
|
||||||
|
install_dir,
|
||||||
|
} => Some((version_name, install_dir)),
|
||||||
|
_ => None,
|
||||||
|
} {
|
||||||
|
db_handle
|
||||||
|
.applications
|
||||||
|
.transient_statuses
|
||||||
|
.insert(meta.clone(), ApplicationTransientStatus::Uninstalling {});
|
||||||
|
|
||||||
|
drop(db_handle);
|
||||||
|
|
||||||
|
let app_handle = app_handle.clone();
|
||||||
|
spawn(move || {
|
||||||
|
if let Err(e) = remove_dir_all(install_dir) {
|
||||||
|
error!("{e}");
|
||||||
|
} else {
|
||||||
|
let mut db_handle = borrow_db_mut_checked();
|
||||||
|
db_handle.applications.transient_statuses.remove(&meta);
|
||||||
|
db_handle
|
||||||
|
.applications
|
||||||
|
.installed_game_version
|
||||||
|
.remove(&meta.id);
|
||||||
|
db_handle
|
||||||
|
.applications
|
||||||
|
.game_statuses
|
||||||
|
.insert(meta.id.clone(), GameDownloadStatus::Remote {});
|
||||||
|
let _ = db_handle.applications.transient_statuses.remove(&meta);
|
||||||
|
|
||||||
|
push_game_update(
|
||||||
|
&app_handle,
|
||||||
|
&meta.id,
|
||||||
|
None,
|
||||||
|
GameStatusManager::fetch_state(&meta.id, &db_handle),
|
||||||
|
);
|
||||||
|
|
||||||
|
debug!("uninstalled game id {}", &meta.id);
|
||||||
|
app_emit!(&app_handle, "update_library", ());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
warn!("invalid previous state for uninstall, failing silently.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_current_meta(game_id: &String) -> Option<DownloadableMetadata> {
|
||||||
|
borrow_db_checked()
|
||||||
|
.applications
|
||||||
|
.installed_game_version
|
||||||
|
.get(game_id)
|
||||||
|
.cloned()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn on_game_complete(
|
||||||
|
meta: &DownloadableMetadata,
|
||||||
|
install_dir: String,
|
||||||
|
app_handle: &AppHandle,
|
||||||
|
) -> Result<(), RemoteAccessError> {
|
||||||
|
// 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(
|
||||||
|
&["/api/v1/client/game/version"],
|
||||||
|
&[
|
||||||
|
("id", &meta.id),
|
||||||
|
("version", meta.version.as_ref().unwrap()),
|
||||||
|
],
|
||||||
|
)?;
|
||||||
|
let response = client
|
||||||
|
.get(response)
|
||||||
|
.header("Authorization", generate_authorization_header())
|
||||||
|
.send()?;
|
||||||
|
|
||||||
|
let game_version: GameVersion = response.json()?;
|
||||||
|
|
||||||
|
let mut handle = borrow_db_mut_checked();
|
||||||
|
handle
|
||||||
|
.applications
|
||||||
|
.game_versions
|
||||||
|
.entry(meta.id.clone())
|
||||||
|
.or_default()
|
||||||
|
.insert(meta.version.clone().unwrap(), game_version.clone());
|
||||||
|
handle
|
||||||
|
.applications
|
||||||
|
.installed_game_version
|
||||||
|
.insert(meta.id.clone(), meta.clone());
|
||||||
|
|
||||||
|
drop(handle);
|
||||||
|
|
||||||
|
let status = if game_version.setup_command.is_empty() {
|
||||||
|
GameDownloadStatus::Installed {
|
||||||
|
version_name: meta.version.clone().unwrap(),
|
||||||
|
install_dir,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GameDownloadStatus::SetupRequired {
|
||||||
|
version_name: meta.version.clone().unwrap(),
|
||||||
|
install_dir,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut db_handle = borrow_db_mut_checked();
|
||||||
|
db_handle
|
||||||
|
.applications
|
||||||
|
.game_statuses
|
||||||
|
.insert(meta.id.clone(), status.clone());
|
||||||
|
drop(db_handle);
|
||||||
|
app_emit!(
|
||||||
|
app_handle,
|
||||||
|
&format!("update_game/{}", meta.id),
|
||||||
|
GameUpdateEvent {
|
||||||
|
game_id: meta.id.clone(),
|
||||||
|
status: (Some(status), None),
|
||||||
|
version: Some(game_version),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn push_game_update(
|
||||||
|
app_handle: &AppHandle,
|
||||||
|
game_id: &String,
|
||||||
|
version: Option<GameVersion>,
|
||||||
|
status: GameStatusWithTransient,
|
||||||
|
) {
|
||||||
|
if let Some(GameDownloadStatus::Installed { .. } | GameDownloadStatus::SetupRequired { .. }) =
|
||||||
|
&status.0
|
||||||
|
&& version.is_none()
|
||||||
|
{
|
||||||
|
panic!("pushed game for installed game that doesn't have version information");
|
||||||
|
}
|
||||||
|
|
||||||
|
app_emit!(
|
||||||
|
app_handle,
|
||||||
|
&format!("update_game/{game_id}"),
|
||||||
|
GameUpdateEvent {
|
||||||
|
game_id: game_id.clone(),
|
||||||
|
status,
|
||||||
|
version,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct FrontendGameOptions {
|
||||||
|
launch_string: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FrontendGameOptions {
|
||||||
|
pub fn launch_string(&self) -> &String {
|
||||||
|
&self.launch_string
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user