Skip to content

Commit

Permalink
Treat 6328 assets as optional in the WPILib version
Browse files Browse the repository at this point in the history
Don't download the assets, but don't delete them if they're found
  • Loading branch information
jwbonner committed Oct 16, 2023
1 parent 3fc5a8a commit 4362026
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/main/Constants.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { app } from "electron";
import path from "path";
import Preferences from "../shared/Preferences";
import { DISTRIBUTOR, Distributor } from "../shared/buildConstants";

// General
export const REPOSITORY = "Mechanical-Advantage/AdvantageScope";
export const ASSETS_REPOSITORY = "Mechanical-Advantage/AdvantageScopeAssets";
export const ASSET_TAGS = new Set([
"default-assets-v1",
...(DISTRIBUTOR === Distributor.FRC6328 ? ["frc-6328-assets-v1"] : [])
]);
export const ASSET_TAG_DEFAULT = "default-assets-v1";
export const ASSET_TAG_FRC6328 = "frc-6328-assets-v1";
export const PREFS_FILENAME = path.join(app.getPath("userData"), "prefs.json");
export const STATE_FILENAME = path.join(
app.getPath("userData"),
Expand Down
11 changes: 7 additions & 4 deletions src/main/assetsDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import checkDiskSpace from "check-disk-space";
import download from "download";
import fs from "fs";
import path from "path";
import { ASSETS_REPOSITORY, ASSET_TAGS, AUTO_ASSETS } from "./Constants";
import { DISTRIBUTOR, Distributor } from "../shared/buildConstants";
import { ASSETS_REPOSITORY, ASSET_TAG_DEFAULT, ASSET_TAG_FRC6328, AUTO_ASSETS } from "./Constants";

const REQUIRED_SPACE_GB = 25;
const FAILURE_TIMEOUT_MS = 30 * 1000; // 30 seconds
Expand Down Expand Up @@ -59,6 +60,7 @@ export function getAssetDownloadStatus() {
interface AssetDownloadInfo {
source: string;
target: string;
optional: boolean;
}

/** Gets the set of assets to download from GitHub. */
Expand Down Expand Up @@ -86,11 +88,12 @@ async function getAssetInfo(): Promise<AssetDownloadInfo[]> {
// Extract download info
let downloadInfo: AssetDownloadInfo[] = [];
releaseData.forEach((release) => {
if (ASSET_TAGS.has(release.tag_name)) {
if (release.tag_name === ASSET_TAG_DEFAULT || release.tag_name === ASSET_TAG_FRC6328) {
release.assets.forEach((asset) => {
downloadInfo.push({
target: path.join(AUTO_ASSETS, asset.name.slice(0, asset.name.length - 4)), // Remove ".zip"
source: asset.browser_download_url
source: asset.browser_download_url,
optional: DISTRIBUTOR === Distributor.WPILib && release.tag_name === ASSET_TAG_FRC6328
});
});
}
Expand All @@ -103,7 +106,7 @@ async function updateLocalAssets(downloadInfo: AssetDownloadInfo[]) {
// Download new assets
await Promise.all(
downloadInfo
.filter((assetInfo) => !fs.existsSync(assetInfo.target))
.filter((assetInfo) => !assetInfo.optional && !fs.existsSync(assetInfo.target))
.map((assetInfo) => download(assetInfo.source, assetInfo.target, { extract: true }))
);

Expand Down

0 comments on commit 4362026

Please sign in to comment.