Skip to content

Commit

Permalink
added image cache breaker for kart, fixed images being deleted on ove…
Browse files Browse the repository at this point in the history
…rlay update, add reset button, removed the path key from the project, added some stuff for windows people in the config
  • Loading branch information
MADMAN-Modding committed Aug 25, 2024
1 parent 1415c35 commit faef1b2
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 130 deletions.
6 changes: 3 additions & 3 deletions app/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import 'package:hexcolor/hexcolor.dart';
class Constants {
static JSONHandler jsonHandler = JSONHandler();

static String slashType = Platform.isWindows ? r'\\' + r'\\' : "/";
static String slashType = Platform.isWindows ? r'\\' : "/";

static HTTPHandler httpHandler = HTTPHandler();

static String executableDirectory =
File(Platform.resolvedExecutable).parent.path;

static String overlayDirectory =
"$executableDirectory${slashType}FalconsEsportsOverlays";
"$executableDirectory${slashType}FalconsEsportsOverlays-main";

static String imagePath = "$overlayDirectory${slashType}Esports-Logo.png";
static String imagePath = "$executableDirectory${slashType}Esports-Logo.png";

static HexColor appTheme = HexColor(jsonHandler.readConfig("appTheme"));

Expand Down
35 changes: 26 additions & 9 deletions app/lib/handlers/download_handler.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';
import 'package:archive/archive_io.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:permission_handler/permission_handler.dart';
import 'package:falcons_esports_overlays_controller/constants.dart'
Expand All @@ -8,7 +9,7 @@ import 'package:falcons_esports_overlays_controller/constants.dart'
class DownloadHandler {
static download(String path) async {
String slashType = constants.Constants.slashType;
print(path);

if (!Platform.isAndroid || await Permission.storage.request().isGranted) {
await http
.get(Uri.https('codeload.github.com',
Expand All @@ -18,27 +19,43 @@ class DownloadHandler {
.writeAsBytesSync(response.bodyBytes);
});

// Extract stff
extractor(path);

// Delete Stuff
File("$path${slashType}overlay.zip").deleteSync();

// Try to delete the directory if its already there
try {
Directory("$path${slashType}FalconsEsportsOverlays")
.deleteSync(recursive: true);
} catch (e) {}

Directory("$path${slashType}FalconsEsportsOverlays-main")
.renameSync("$path${slashType}FalconsEsportsOverlays");

// Remove the app dir cause it isn't needed
try {
Directory("$path${slashType}FalconsEsportsOverlays-main")
Directory("$path${slashType}FalconsEsportsOverlays-main${slashType}app")
.deleteSync(recursive: true);
} catch (e) {}

try {
Directory("$path${slashType}FalconsEsportsOverlays${slashType}app")
.deleteSync(recursive: true);
} catch (e) {}
// Makes a new image file and then overwrites it if it didn't already exist
if (!File("$path${slashType}Esports-Logo.png").existsSync()) {
// Makes the new file
FileImage(File("$path${slashType}Esports-Logo.png"))
.file
.writeAsBytesSync(FileImage(File(
"$path${slashType}FalconsEsportsOverlays-main${slashType}images${slashType}Esports-Logo.png"))
.file
.readAsBytesSync());
}

// Overwrites the downloaded logo
FileImage(File(
"$path${slashType}FalconsEsportsOverlays-main${slashType}images${slashType}Esports-Logo.png"))
.file
.writeAsBytesSync(FileImage(File(
"$path${slashType}FalconsEsportsOverlays-main${slashType}images${slashType}Esports-Logo.png"))
.file
.readAsBytesSync());
}
}

Expand Down
12 changes: 5 additions & 7 deletions app/lib/handlers/json_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class JSONHandler {

constants.Constants.executableDirectory = dir.path;
constants.Constants.overlayDirectory =
"$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays";
"$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays-main";

executableDirectory = constants.Constants.executableDirectory;
}
Expand All @@ -44,15 +44,13 @@ class JSONHandler {
print("Can't find file :( $e \nmaking a new config");
}
if (!Platform.isAndroid || await Permission.storage.request().isGranted) {
String path = executableDirectory;
File('$executableDirectory${constants.Constants.slashType}config.json')
.create(recursive: true)
// This initializes the config stuff
.whenComplete(() => File(
'$executableDirectory${constants.Constants.slashType}config.json')
.writeAsString('''
{
"path": "$path",
"appTheme": "#bf0f35",
"ssbuChecked": true,
"kartChecked": true,
Expand All @@ -79,7 +77,7 @@ class JSONHandler {
// This is the same as the config but for the overlay
try {
overlayJSON = File(
'$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays${constants.Constants.slashType}json${constants.Constants.slashType}overlay.json')
'$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays-main${constants.Constants.slashType}json${constants.Constants.slashType}overlay.json')
.readAsJsonSync();
} catch (e) {
if (kDebugMode) {
Expand All @@ -97,7 +95,7 @@ class JSONHandler {
if (!isWriting) {
isWriting = true;
overlayJSON[key] = data;
File('$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays${constants.Constants.slashType}json${constants.Constants.slashType}overlay.json')
File('$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays-main${constants.Constants.slashType}json${constants.Constants.slashType}overlay.json')
.writeAsStringSync(jsonEncode(overlayJSON));
}
// Tries to prevent the overlay being written to twice, idk if it really made improvements
Expand Down Expand Up @@ -198,7 +196,7 @@ class JSONHandler {

try {
// Initializes values
File('$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays${constants.Constants.slashType}json${constants.Constants.slashType}overlay.json')
File('$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays-main${constants.Constants.slashType}json${constants.Constants.slashType}overlay.json')
.writeAsStringSync('''
{
"teamNameLeft": "DC Falcons Red",
Expand All @@ -218,7 +216,7 @@ class JSONHandler {

// Loads the overlay
overlayJSON = File(
'$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays${constants.Constants.slashType}json${constants.Constants.slashType}overlay.json')
'$executableDirectory${constants.Constants.slashType}FalconsEsportsOverlays-main${constants.Constants.slashType}json${constants.Constants.slashType}overlay.json')
.readAsJsonSync();
} catch (e) {
return;
Expand Down
45 changes: 10 additions & 35 deletions app/lib/pages/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,26 @@ class _ControlsPage extends State<ConfigPage> {
String codePath = constants.Constants.overlayDirectory;
String imagePath = constants.Constants.imagePath;

// Creates objects for the jsonHandler and for changing the text
TextEditingController gitDirectory = TextEditingController();

// ImagePicker library object
ImagePicker picker = ImagePicker();

@override
Widget build(BuildContext context) {
TextEditingController directory = TextEditingController();
TextEditingController appTheme = TextEditingController();

directory.text = constants.Constants.jsonHandler.configJSON["path"];
codePath = directory.text;
appTheme.text =
"${constants.Constants.jsonHandler.configJSON["appTheme"].replaceFirst("FF", "")}";

FileImage logo;

try {
logo = FileImage(File(
"${constants.Constants.overlayDirectory}${constants.Constants.slashType}images${constants.Constants.slashType}Esports-Logo.png"));
"${constants.Constants.executableDirectory}${constants.Constants.slashType}Esports-Logo.png"));
} catch (e) {
logo = FileImage(File("path"));
}
if (!Platform.isAndroid) {
return appPage(directory, logo, appTheme);
return appPage(logo, appTheme);
}

return SizedBox(
Expand All @@ -57,8 +51,7 @@ class _ControlsPage extends State<ConfigPage> {
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: appPage(directory, logo, appTheme)),
scrollDirection: Axis.horizontal, child: appPage(logo, appTheme)),
),
);
}
Expand All @@ -85,29 +78,10 @@ class _ControlsPage extends State<ConfigPage> {
);
}

Widget appPage(TextEditingController directory, FileImage logo,
TextEditingController appTheme) {
Widget appPage(FileImage logo, TextEditingController appTheme) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// Code Directory
if (!Platform.isAndroid) ...[
const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.only(left: 13),
child: Text(
"This is the directory that contains all the code",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 17),
),
),
],
),
],
// Makes the image button and the text
Row(
children: [
Expand Down Expand Up @@ -136,18 +110,19 @@ class _ControlsPage extends State<ConfigPage> {
File(imagePath.replaceAll(r"\", r"\\")))
.file
.readAsBytesSync());

File("${constants.Constants.overlayDirectory}${constants.Constants.slashType}images${constants.Constants.slashType}Esports-Logo.png")
.writeAsBytesSync(
logo.file.readAsBytesSync());
} catch (e) {}
}
// Sets the text equal to the path
directory.text = codePath.toString();

// Clears the cache
logo.evict();
},
),
),
DefaultText.text(
"Set the image you would like to use for the overlay icon. "),
"Set the image you would like to use for the overlay icon. ${Platform.isWindows ? "\nThere's a bug with flutter on Windows,\nyou need to change pages, to see the logo change on this page" : ""}"),
],
),
// Displays the logo
Expand Down Expand Up @@ -217,7 +192,7 @@ class _ControlsPage extends State<ConfigPage> {
],
)
],
)
),
],
),
],
Expand Down
18 changes: 18 additions & 0 deletions app/lib/pages/download.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:io';
import 'package:falcons_esports_overlays_controller/constants.dart'
as constants;
import 'package:falcons_esports_overlays_controller/handlers/download_handler.dart';
Expand Down Expand Up @@ -34,6 +35,23 @@ class _DownloadPage extends State<DownloadPage> {
Padding(
padding: const EdgeInsets.all(2.0),
child: buttonAction("Update"),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: ElevatedButton(
onPressed: () async {
NotificationHandler.notification(
context, "Starting Reset...");
try {
File("${constants.Constants.executableDirectory}${constants.Constants.slashType}Esports-Logo.png")
.delete();
} catch (e) {}
await DownloadHandler.download(chosenPath);

NotificationHandler.notification(
context, "Overlays Reset");
},
child: const Text("Reset Overlays")),
)
],
),
Expand Down
8 changes: 4 additions & 4 deletions app/macos/Flutter/ephemeral/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/home/mad/Documents/Apps/flutter"
export "FLUTTER_APPLICATION_PATH=/home/mad/Documents/Coding/Projects/FalconsEsportsOverlays/app"
export "FLUTTER_ROOT=D:\Programs\flutter"
export "FLUTTER_APPLICATION_PATH=D:\Coding\Projects\FalconsEsportsOverlays\app"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=2.2.0"
export "FLUTTER_BUILD_NUMBER=2.2.0"
export "FLUTTER_BUILD_NAME=2.9.0"
export "FLUTTER_BUILD_NUMBER=2.9.0"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
Expand Down
Loading

0 comments on commit faef1b2

Please sign in to comment.