Skip to content

Commit

Permalink
Merge pull request #44 from KizKizz/backend-rework
Browse files Browse the repository at this point in the history
new adder update
  • Loading branch information
KizKizz authored Jan 19, 2023
2 parents f448271 + c23405f commit c40c2c3
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 191 deletions.
Binary file added checksum/d4455ebc2bef618f29106da7692ebc1a
Binary file not shown.
28 changes: 14 additions & 14 deletions lib/application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:pso2_mod_manager/state_provider.dart';
String newVersion = '';
String patchNotes = '';
List<String> patchNoteSplit = [];
int refSheetsNewVersion = -1;

class ApplicationConfig {
//App version Check
Expand All @@ -37,7 +38,7 @@ class ApplicationConfig {

Future<Map<String, dynamic>> loadJsonFromGithub() async {
String jsonResponse = '{"null": "null"}';
int timeout = 5;
int timeout = 10;
try {
http.Response response = await http.get(Uri.parse('https://raw.githubusercontent.com/KizKizz/pso2_mod_manager/main/app_version_check/app_version.json')).timeout(Duration(seconds: timeout));
if (response.statusCode == 200) {
Expand All @@ -58,28 +59,27 @@ class ApplicationConfig {
final jsonVal = await loadRefSheetsJsonFromGithub();
if (jsonVal.entries.first.key != 'null') {
String newVersionValue = jsonVal.entries.firstWhere((element) => element.key == 'version').value;
List<String> newVersionValues = newVersionValue.split('.');
int major = int.parse(newVersionValues[0]);
int minor = int.parse(newVersionValues[1]);
int patch = int.parse(newVersionValues[2]);
if (major > int.parse(currentVersionValues[0]) || minor > int.parse(currentVersionValues[1]) || patch > int.parse(currentVersionValues[2])) {
newVersion = newVersionValue;
String tempPatchNote = jsonVal.entries.firstWhere((element) => element.key == 'description').value.toString();
patchNotes = tempPatchNote.replaceFirst('[', '', 0).replaceFirst(']', '', patchNotes.length);
patchNoteSplit = patchNotes.split(', ');
//debugPrint('Response: ${patchNotes.first}');
Provider.of<StateProvider>(context, listen: false).isUpdateAvailableTrue();
if (refSheetsVersion < int.parse(newVersionValue)) {
refSheetsNewVersion = int.parse(newVersionValue);
Provider.of<StateProvider>(context, listen: false).refSheetsUpdateAvailableTrue();
}

// String tempPatchNote = jsonVal.entries.firstWhere((element) => element.key == 'description').value.toString();
// patchNotes = tempPatchNote.replaceFirst('[', '', 0).replaceFirst(']', '', patchNotes.length);
// patchNoteSplit = patchNotes.split(', ');
//debugPrint('Response: ${patchNotes.first}');

}
}

Future<Map<String, dynamic>> loadRefSheetsJsonFromGithub() async {
String jsonResponse = '{"null": "null"}';
int timeout = 5;
try {
http.Response response = await http.get(Uri.parse('https://raw.githubusercontent.com/KizKizz/pso2_mod_manager/main/app_version_check/app_version.json')).timeout(Duration(seconds: timeout));
http.Response response =
await http.get(Uri.parse('https://raw.githubusercontent.com/KizKizz/pso2_mod_manager/main/app_version_check/ref_sheets_version.json')).timeout(Duration(seconds: timeout));
if (response.statusCode == 200) {
jsonResponse = await http.read(Uri.parse('https://raw.githubusercontent.com/KizKizz/pso2_mod_manager/main/app_version_check/app_version.json'));
jsonResponse = await http.read(Uri.parse('https://raw.githubusercontent.com/KizKizz/pso2_mod_manager/main/app_version_check/ref_sheets_version.json'));
}
} on TimeoutException catch (e) {
debugPrint('Timeout Error: $e');
Expand Down
2 changes: 1 addition & 1 deletion lib/file_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ Future<void> modFilesAdder(context, List<List<String>> sortedList, XFile itemIco
} else {
itemName = sortedLine[2];
}
List<String> mainNames = sortedLine[3].split('|');
//List<String> mainNames = sortedLine[3].split('|');
List<String> subNames = sortedLine[4].split('|');
List<String> fileInfos = sortedLine[5].split('|');
String newItemPath = '$modsDirPath$s$category$s$itemName';
Expand Down
20 changes: 17 additions & 3 deletions lib/item_ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import 'dart:convert';
import 'dart:io';

import 'package:cross_file/cross_file.dart';
import 'package:dio/dio.dart';
import 'package:provider/provider.dart';
import 'package:pso2_mod_manager/state_provider.dart';

import 'main.dart';
import 'package:path/path.dart' as p;

String refSheetsDirPath = '${Directory.current.path}${s}ItemRefSheets$s';
String ngsRefSheetsDirPath = '${refSheetsDirPath}Player${s}NGS$s';
List<List<String>> ngsRefSheetsList = [];
String refSheetsDirPath = '${Directory.current.path}${s}ItemRefSheets';
//String playerRefSheetsDirPath = '$refSheetsDirPath${s}Player';
List<List<String>> itemRefSheetsList = [];

Future<List<List<String>>> popSheetsList(String csvDirPath) async {
List<FileSystemEntity> dirList = Directory(csvDirPath).listSync(recursive: true).toList();
Expand All @@ -25,3 +28,14 @@ Future<List<List<String>>> popSheetsList(String csvDirPath) async {

return csvList;
}

Future<void> downloadNewRefSheets(context, List<String> filePaths) async {
final dio = Dio();
for (var path in filePaths) {
String localPath = path.replaceAll(s, '/');
String githubPath = localPath.replaceFirst(refSheetsDirPath.replaceAll(s, '/'), 'https://raw.githubusercontent.com/KizKizz/pso2_mod_manager/main/ItemRefSheets');

await dio.download(githubPath, path);
Provider.of<StateProvider>(context, listen: false).refSheetsCountUp();
}
}
220 changes: 60 additions & 160 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:io';

import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:dart_vlc/dart_vlc.dart';
import 'package:dio/dio.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -55,6 +56,7 @@ String langDropDownSelected = '';
List<String> topBtnMenuItems = [];
String s = '/';
String appVersion = '';
int refSheetsVersion = -1;
String? checkSumFilePath;
FilePickerResult? checksumLocation;
bool _previewWindowVisible = true;
Expand All @@ -66,6 +68,7 @@ var dataStreamController = StreamController();
TextEditingController newSetTextController = TextEditingController();
TextEditingController newLangTextController = TextEditingController();
final newSetFormKey = GlobalKey<FormState>();
List<String> localRefSheetsList = [];

Future<void> main() async {
DartVLC.initialize();
Expand Down Expand Up @@ -155,7 +158,9 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
}
windowManager.addListener(this);
getAppVer();
getRefSheetsVersion();
ApplicationConfig().checkForUpdates(context);
ApplicationConfig().checkRefSheetsForUpdates(context);
languagePackCheck();
miscCheck();
//mainPathsCheck();
Expand All @@ -169,6 +174,11 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
appVersion = packageInfo.version;
}

Future<void> getRefSheetsVersion() async {
final prefs = await SharedPreferences.getInstance();
refSheetsVersion = (prefs.getInt('refSheetsVersion') ?? 0);
}

@override
Future<void> onWindowResized() async {
Size curWindowSize = await windowManager.getSize();
Expand Down Expand Up @@ -280,130 +290,8 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
}
}

// void mainPathsCheck() async {
// final prefs = await SharedPreferences.getInstance();
// //prefs.clear();
// binDirPath = prefs.getString('binDirPath') ?? '';
// mainModManDirPath = prefs.getString('mainModManDirPath') ?? '';

// if (binDirPath.isEmpty || mainModManDirPath.isEmpty) {
// await getUILanguage();
// }

// if (mainModManDirPath.isEmpty) {
// await getMainModManDirPath();
// }

// if (binDirPath.isEmpty) {
// await getDirPath();
// }
// }

// Future<void> dirPathCheck() async {
// final prefs = await SharedPreferences.getInstance();
// //prefs.clear();
// binDirPath = prefs.getString('binDirPath') ?? '';
// mainModManDirPath = prefs.getString('mainModManDirPath') ?? '';

// if (mainModManDirPath.isNotEmpty && Directory(mainModManDirPath).existsSync()) {
// //Fill in paths
// mainModDirPath = '$mainModManDirPath${s}PSO2 Mod Manager';
// modsDirPath = '$mainModDirPath${s}Mods';
// backupDirPath = '$mainModDirPath${s}Backups';
// checksumDirPath = '$mainModDirPath${s}Checksum';
// modSettingsPath = '$mainModDirPath${s}PSO2ModManSettings.json';
// modSetsSettingsPath = '$mainModDirPath${s}PSO2ModManModSets.json';
// deletedItemsPath = '$mainModDirPath${s}Deleted Items';
// //Check if exist, create dirs
// if (!Directory(mainModDirPath).existsSync()) {
// await Directory(mainModDirPath).create(recursive: true);
// }
// if (!Directory(modsDirPath).existsSync()) {
// await Directory(modsDirPath).create(recursive: true);
// await Directory('$modsDirPath${s}Accessories').create(recursive: true);
// await Directory('$modsDirPath${s}Basewears').create(recursive: true);
// await Directory('$modsDirPath${s}Body Paints').create(recursive: true);
// await Directory('$modsDirPath${s}Emotes').create(recursive: true);
// await Directory('$modsDirPath${s}Face Paints').create(recursive: true);
// await Directory('$modsDirPath${s}Innerwears').create(recursive: true);
// await Directory('$modsDirPath${s}Misc').create(recursive: true);
// await Directory('$modsDirPath${s}Motions').create(recursive: true);
// await Directory('$modsDirPath${s}Outerwears').create(recursive: true);
// await Directory('$modsDirPath${s}Setwears').create(recursive: true);
// }
// if (!Directory(backupDirPath).existsSync()) {
// await Directory(backupDirPath).create(recursive: true);
// }
// if (!Directory('$backupDirPath${s}win32_na').existsSync()) {
// await Directory('$backupDirPath${s}win32_na').create(recursive: true);
// }
// if (!Directory('$backupDirPath${s}win32reboot_na').existsSync()) {
// await Directory('$backupDirPath${s}win32reboot_na').create(recursive: true);
// }
// if (!Directory(checksumDirPath).existsSync()) {
// await Directory(checksumDirPath).create(recursive: true);
// }
// if (!File(deletedItemsPath).existsSync()) {
// await Directory(deletedItemsPath).create(recursive: true);
// }
// if (!File(modSettingsPath).existsSync()) {
// await File(modSettingsPath).create(recursive: true);
// }
// if (!File(modSetsSettingsPath).existsSync()) {
// await File(modSetsSettingsPath).create(recursive: true);
// }

// setState(() {
// context.read<StateProvider>().mainModManPathFoundTrue();
// });

// //Checksum check
// if (checkSumFilePath == null) {
// final filesInCSFolder = Directory(checksumDirPath).listSync().whereType<File>();
// for (var file in filesInCSFolder) {
// if (p.extension(file.path) == '') {
// checkSumFilePath = file.path;
// }
// }
// }
// }
// if (binDirPath.isNotEmpty && Directory(binDirPath).existsSync()) {
// setState(() {
// context.read<StateProvider>().mainBinFoundTrue();
// });
// }
// }

// Future<void> getDirPath() async {
// binDirDialog(context, 'Error', curLangText!.pso2binNotFoundPopupText, false);
// }

// Future<void> getMainModManDirPath() async {
// mainModManDirDialog(context, curLangText!.modmanFolderNotFoundLabelText, curLangText!.modmanFolderNotFoundText, false);
// }

@override
Widget build(BuildContext context) {
// miscCheck();
// if (binDirPath.isNotEmpty && mainModManDirPath.isNotEmpty) {
// dirPathCheck();
// }

// if (curLangText == null) {
// //getUILanguage();
// }

// WidgetsBinding.instance.addTimingsCallback((_) async {
// await miscCheck();
// if (binDirPath.isNotEmpty && mainModManDirPath.isNotEmpty && await Directory(binDirPath).exists() && await Directory(mainModManDirPath).exists()) {
// debugPrint(Directory(mainModManDirPath).exists().toString());
// await dirPathCheck();
// }
// await Future.delayed(const Duration(milliseconds: 500));
// if (curLangText == null) {
// await getUILanguage();
// }
// });
return Scaffold(
body: Column(
children: [
Expand Down Expand Up @@ -532,7 +420,7 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
setState(() {});
}
} else {
await launchUrl(Uri.parse('file:$checksumDirPath'));
//await launchUrl(Uri.parse('file:$checksumDirPath'));
}
}),
child: checkSumFilePath != null
Expand Down Expand Up @@ -1034,44 +922,56 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
actions: const [SizedBox()],
)),

Expanded(child: curLangText == null ? const LangLoadingPage() : const PathsLoadingPage())
//New Ref sheets
if (context.watch<StateProvider>().refSheetsUpdateAvailable)
ScaffoldMessenger(
child: MaterialBanner(
backgroundColor: Theme.of(context).canvasColor,
elevation: 0,
padding: const EdgeInsets.all(0),
leadingPadding: const EdgeInsets.only(left: 15, right: 5),
leading: Icon(
Icons.newspaper,
color: MyApp.themeNotifier.value == ThemeMode.light ? Theme.of(context).primaryColorDark : Colors.amberAccent,
),
content: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (context.watch<StateProvider>().refSheetsCount < 1)
Text(
'New update for item references available',
style: TextStyle(color: MyApp.themeNotifier.value == ThemeMode.light ? Theme.of(context).primaryColorDark : Colors.amberAccent, fontWeight: FontWeight.w500),
),
if (context.watch<StateProvider>().refSheetsCount > 0)
Text(
'Downloading: ${context.watch<StateProvider>().refSheetsCount} files of ${localRefSheetsList.length}',
style: TextStyle(color: MyApp.themeNotifier.value == ThemeMode.light ? Theme.of(context).primaryColorDark : Colors.amberAccent, fontWeight: FontWeight.w500),
),
ElevatedButton(
onPressed: (() {
//Indexing files

for (var file in Directory('$refSheetsDirPath${s}Player').listSync(recursive: true).where((element) => p.extension(element.path) == '.csv')) {
localRefSheetsList.add(file.path);
}

downloadNewRefSheets(context, localRefSheetsList).then((_) async {
//final prefs = await SharedPreferences.getInstance();
//prefs.setInt('refSheetsVersion', refSheetsNewVersion);
//print('complete');
Provider.of<StateProvider>(context, listen: false).refSheetsUpdateAvailableFalse();
Provider.of<StateProvider>(context, listen: false).refSheetsCountReset();
});

//Switching Page
//const LangLoadingPage()
// ? Expanded(
// child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: const [
// Text(
// 'Loading UI',
// style: TextStyle(fontSize: 20),
// ),
// SizedBox(
// height: 20,
// ),
// CircularProgressIndicator(),
// ],
// ),
// )
// : context.watch<StateProvider>().isMainBinFound && context.watch<StateProvider>().isMainModManPathFound
// ? const DataLoadingPage()
// : Expanded(
// child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Text(
// curLangText!.waitingUserActionText,
// style: const TextStyle(fontSize: 20),
// ),
// const SizedBox(
// height: 20,
// ),
// const CircularProgressIndicator(),
// ],
// ),
// ),
setState(() {});
}),
child: const Text('Download Update')),
],
),
actions: const [SizedBox()],
)),

Expanded(child: curLangText == null ? const LangLoadingPage() : const PathsLoadingPage())
],
),
);
Expand Down
Loading

0 comments on commit c40c2c3

Please sign in to comment.