Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
Fixed github collection update bug + added new balance mod robot fixe…
Browse files Browse the repository at this point in the history
…s mod.
  • Loading branch information
rob5300 committed Oct 8, 2021
1 parent 01fe2f7 commit 36ade13
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 85 deletions.
Binary file added images/backgrounds/bmod_robots_bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/logos/modcirclelogos/bmod_robots_icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 32 additions & 2 deletions internal/mods.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1.38,
"version": 1.39,
"mods": [
{
"name": "Creators.TF",
Expand Down Expand Up @@ -254,7 +254,7 @@
},
"items": [
{
"modname": "UniqueRockets",
"modname": "Unique Rockets",
"type": "github",
"owner": "AtomicTEM",
"name": "Unique-Rockets",
Expand All @@ -277,6 +277,36 @@
]
}
]
},
{
"name": "Manned Machines Robot Model Fixes",
"blurb": "Fixes for the Manned Machines Mode",
"minLauncherVersion": "0.3.0",
"icon": "images/logos/modcirclelogos/bmod_robots_icon.jpg",
"titleimage": "",
"backgroundimage": "images/backgrounds/bmod_robots_bg.jpg",
"backgroundBlendMode": "soft-light",
"bordercolor": "#6969FF",
"backgroundposX": "center",
"backgroundposY": "bottom",
"website": "https://www.balancemod.tf/",
"github": "",
"twitter": "",
"instagram": "",
"discord": "",
"serverlistproviders": [1756],
"isMod": false,
"gameId": "440",
"contenttext": "Fixes for the Manned Machines Mode. Playable on Balancemod Servers.",
"install": {
"modname": "Manned Machines Robot Model Fixes",
"type": "jsonlist",
"get_url": "https://fastdl.creators.tf/launcher/robot_model_fixes.json",
"cloudflarebypass": true,
"targetdirectory": "{tf2_dir}/tf/custom/",
"version_property_name": "Version",
"install_url_property_name": "DownloadLink"
}
}
]
}
6 changes: 3 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import patchnotesPage from "./patchnotes-page/patchnotespage";
import ServerListPage from "./serverlist-page/serverlistpage";
import mod_manager from "./modules/mod_manager";
import Utilities from "./modules/utilities";
import { ModListLoader, ModList, ConfigType } from "./modules/mod_list_loader";
import Config from "./modules/config";
import { ModListLoader, ModList } from "./modules/mod_list_loader";
import Config, {ConfigObject} from "./modules/config";

// There are 6 levels of logging: error, warn, info, verbose, debug and silly
import log from "electron-log";
Expand All @@ -24,7 +24,7 @@ const majorErrorMessageEnd = "\nIf this error persists, please report it on our
class Main {
public static mainWindow: BrowserWindow;
public static app: App;
public static config: ConfigType;
public static config: ConfigObject;
public static screenWidth: number;
public static screenHeight: number;
public static minWindowWidth: number;
Expand Down
26 changes: 19 additions & 7 deletions modules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,33 @@ import FsExtensions from "./fs_extensions";
//Home made regex to find a path. May not be perfect.
const pathStringRegex = new RegExp(/("(\S+[:]+[\S]+)")/, "g");

class Config {
public static config: any | null
export class ConfigObject {
steam_directory?: string;
tf2_directory?: string;
current_mod_versions: ConfigModVersion[];
}

export class ConfigModVersion {
name: string;
version: string | number;
versionDisplay: string;
collectionversion?: string;
}

export default class Config {

public static config: ConfigObject | null;

//Save the config given.
public static async SaveConfig(_config: any): Promise<any> {
public static async SaveConfig(_config: ConfigObject): Promise<void> {
const filePathFull = await this.GetConfigFullPath();

await promises.writeFile(filePathFull, JSON.stringify(_config), { encoding: "utf8" });
log.log("Config file was saved.");
}

//Get the config from disk.
public static async GetConfig(): Promise<any> {
public static async GetConfig(): Promise<ConfigObject> {
//If config is null, load it.
const filePathFull = await this.GetConfigFullPath();

Expand Down Expand Up @@ -140,7 +154,7 @@ class Config {
//Linux solution is untested
const homedir = process.env.HOME;
const steamPaths = [".steam/steam", ".local/share/steam"];
let existingPath = await getExistingPath(steamPaths);
const existingPath = await getExistingPath(steamPaths);
basedir = path.join(homedir, existingPath);
}
else {
Expand All @@ -149,5 +163,3 @@ class Config {
return basedir;
}
}

export default Config;
67 changes: 14 additions & 53 deletions modules/mod_list_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import log from "electron-log";
import semver from "semver";
import isDev from "electron-is-dev";
import Utilities from "./utilities";
import axios from "axios";

//URLs to try to get mod lists from.
//More than one allows fallbacks.
Expand Down Expand Up @@ -111,46 +112,19 @@ class ModListLoader {
}

private static async TryGetModList(url: string): Promise<ModList> {
return new Promise((resolve) => {
try{
log.log("Trying to get mod list from: " + url);
const data = new Array<any>();
const req = https.get(url, res => {
console.log(`statusCode: ${res.statusCode}`);

res.on("data", (d) => {
if(res.statusCode != 200){
resolve(null);
}
data.push(d);
});

res.on("end", () => {
try {
let parsed;
const buf = Buffer.concat(data);
if (res.statusCode != 200) {
console.log("ERROR! Not parsing " + url);
return;
} else {
parsed = JSON.parse(buf.toString());
}
resolve(parsed);
}
catch (error){
//Json parsing failed soo reject.
log.error(`Failed to parse JSON in TryGetModList request for ${url}, error: ${error.toString()}`);
resolve(null);
}
});
});

req.on("error", (error: string | undefined) => {
log.error("General request error in a TryGetModList request, error: " + error.toString());
resolve(null);
});

req.end();
});
const result = await axios.get(url, {timeout: 8000});
if(result.status == 200 && result.data != null){
log.log(`Success (${result.status}): ${url}`);
return result.data;
}
log.error(`TryGetModList Error: ${result.statusText}`);
}
catch (e) {
log.error(e.toString());
}
return null;
}

public static GetLocalModList(): ModList {
Expand Down Expand Up @@ -253,17 +227,4 @@ class GithubAsset {
size: string
}

class ConfigType {
steam_directory: string;
tf2_directory: string;
current_mod_versions: ModVersion[]
}

class ModVersion {
name: string;
version: number;
versionDisplay?: string;
collectionversion?: string;
}

export { ModListLoader, ModList, ModListEntry, Install, GithubAsset, ConfigType, ModVersion };
export { ModListLoader, ModList, ModListEntry, Install, GithubAsset };
33 changes: 17 additions & 16 deletions modules/mod_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,22 @@ class ModManager {
//Do the update!
log.log("Starting update process...");

const configObj = await config.GetConfig();
const modList = configObj.current_mod_versions;
//Find the current mod version we want
let collectionVersionInstalled: string;
let desiredCollectionVersion: number;
if (IsCollection(this.source_manager.data)) {
//It is an install[] then
modList.forEach(element => {
if (element.name == this.source_manager.data[0].modname) {
//We've found our mod
collectionVersionInstalled = element.collectionversion;
}
});
desiredCollectionVersion = Utilities.FindCollectionNumber(this.source_manager.data, collectionVersionInstalled);
await this.UpdateCurrentMod(desiredCollectionVersion);
if (this.source_manager instanceof GithubCollectionSource || IsCollection(this.source_manager.data)) {
try {
const configObj = await config.GetConfig();
const modList = configObj.current_mod_versions;
//Find the current mod version we want
let collectionVersionInstalled = modList.find(
x => x.name == this.source_manager.data[0].name || x.name == this.source_manager.data[0].modname).collectionversion;

const desiredCollectionVersion = Utilities.FindCollectionNumber(this.source_manager.data, collectionVersionInstalled);
await this.UpdateCurrentMod(desiredCollectionVersion);
}
catch (e) {
await ErrorDialog("Unable to update mod due to error:\n" + e.toString(), "Update Error");
this.FakeClickMod();
return;
}
} else {
await this.UpdateCurrentMod();
}
Expand Down Expand Up @@ -358,7 +359,7 @@ class ModManager {
const result = await this.ModInstall(_url);
if(result){
SetNewModVersion(this.currentModVersionRemote, this.currentModVersionToDisplay, this.currentModData.name);

await config.SaveConfig(Main.config);

this.FakeClickMod();
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "creators-tf-launcher",
"version": "0.2.9",
"version": "0.3.0",
"description": "An easier way to install, update and play TF2 content.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 36ade13

Please sign in to comment.