Skip to content

Commit

Permalink
Merge pull request #13 from KizKizz/backend-rework
Browse files Browse the repository at this point in the history
Backend rework
  • Loading branch information
KizKizz authored Jun 30, 2022
2 parents 0cb3592 + 6b54519 commit 850fd08
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 99 deletions.
3 changes: 3 additions & 0 deletions lib/data_loading_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pso2_mod_manager/file_functions.dart';
import 'package:pso2_mod_manager/home_page.dart';
import 'package:pso2_mod_manager/main.dart';
import 'package:pso2_mod_manager/mods_loader.dart';
import 'package:pso2_mod_manager/state_provider.dart';

class DataLoadingPage extends StatefulWidget {
const DataLoadingPage({Key? key}) : super(key: key);
Expand Down Expand Up @@ -43,6 +45,7 @@ class _DataLoadingPageState extends State<DataLoadingPage> {
cateList = categories(allModFiles);
appliedModsListGet = getAppliedModsList();
iceFiles = dataDir.listSync(recursive: true).whereType<File>().toList();
Provider.of<stateProvider>(context, listen: false).cateListItemCountSetNoListener(cateList.length);
//print('${allModFiles.length} iceFiles Loaded');

return const HomePage();
Expand Down
87 changes: 83 additions & 4 deletions lib/file_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,34 @@ Future<void> dragDropSingleFilesAdd(context, List<XFile> newItemDragDropList, XF
}

List<File> imgList = filesList.where((e) => (p.extension(e.path) == '.jpg' || p.extension(e.path) == '.png') && e.parent.path == file.parent.path).toList();
List<File> vidList = filesList.where((e) => (p.extension(e.path) == '.mp4' || p.extension(e.path) == '.webm') && e.parent.path == file.parent.path).toList();

ModFile newModFile = ModFile('', newItemPath, modName, file.path, iceName, iceParents, '', '', getImagesList(imgList), false, true, true, false, []);
if (imgList.isEmpty || vidList.isEmpty) {
List<String> filePathSplit = file.path.split('$newItemPath\\').last.split('\\');
filePathSplit.insert(0, newItemName!);
String fileName = filePathSplit.removeLast();
String tempPath = file.path.split('\\$fileName').first;
for (var folderPath in filePathSplit.reversed) {
List<File> imgVidGet = Directory(tempPath)
.listSync(recursive: false)
.whereType<File>()
.where((e) => p.extension(e.path) == '.jpg' || p.extension(e.path) == '.png' || p.extension(e.path) == '.mp4' || p.extension(e.path) == '.webm')
.toList();
if (imgVidGet.isNotEmpty) {
for (var file in imgVidGet) {
if ((p.extension(file.path) == '.jpg' || p.extension(file.path) == '.png') && imgList.indexWhere((element) => element.path.split('\\').last == file.path.split('\\').last) == -1) {
imgList.add(file);
}
if ((p.extension(file.path) == '.mp4' || p.extension(file.path) == '.webm') && vidList.indexWhere((element) => element.path.split('\\').last == file.path.split('\\').last) == -1) {
vidList.add(file);
}
}
}
tempPath = tempPath.split('\\$folderPath').first;
}
}

ModFile newModFile = ModFile('', newItemPath, modName, file.path, iceName, iceParents, '', '', getImagesList(imgList), false, true, true, false, vidList);
newModFile.categoryName = selectedCategoryName.toString();
newModFile.categoryPath = catePath;
newModList.add(newModFile);
Expand Down Expand Up @@ -701,9 +727,37 @@ Future<void> dragDropFilesAdd(context, List<XFile> newItemDragDropList, String?
}

List<File> imgList = filesList.where((e) => (p.extension(e.path) == '.jpg' || p.extension(e.path) == '.png') && e.parent.path == file.parent.path).toList();

List<File> vidList = filesList.where((e) => (p.extension(e.path) == '.mp4' || p.extension(e.path) == '.webm') && e.parent.path == file.parent.path).toList();

if (imgList.isEmpty || vidList.isEmpty) {
List<String> filePathSplit = file.path.split('$newItemPath\\').last.split('\\');
if (filePathSplit.isNotEmpty) {
filePathSplit.insert(0, xFile.name);
String fileName = filePathSplit.removeLast();
String tempPath = file.path.split('\\$fileName').first;
for (var folderPath in filePathSplit.reversed) {
List<File> imgVidGet = Directory(tempPath)
.listSync(recursive: false)
.whereType<File>()
.where((e) => p.extension(e.path) == '.jpg' || p.extension(e.path) == '.png' || p.extension(e.path) == '.mp4' || p.extension(e.path) == '.webm')
.toList();
if (imgVidGet.isNotEmpty) {
for (var file in imgVidGet) {
if ((p.extension(file.path) == '.jpg' || p.extension(file.path) == '.png') &&
imgList.indexWhere((element) => element.path.split('\\').last == file.path.split('\\').last) == -1) {
imgList.add(file);
}
if ((p.extension(file.path) == '.mp4' || p.extension(file.path) == '.webm') &&
vidList.indexWhere((element) => element.path.split('\\').last == file.path.split('\\').last) == -1) {
vidList.add(file);
}
}
}
tempPath = tempPath.split('\\$folderPath').first;
}
}
}

ModFile newModFile = ModFile('', newItemPath, modName, file.path, iceName, iceParents, '', '', getImagesList(imgList), false, true, true, false, vidList);
newModFile.categoryName = selectedCategoryName.toString();
newModFile.categoryPath = catePath;
Expand Down Expand Up @@ -825,10 +879,10 @@ Future<void> dragDropModsAdd(context, List<XFile> newModDragDropList, String cur
.toList();
if (imgVidGet.isNotEmpty) {
for (var file in imgVidGet) {
if (p.extension(file.path) == '.jpg' || p.extension(file.path) == '.png') {
if ((p.extension(file.path) == '.jpg' || p.extension(file.path) == '.png') && imgList.indexWhere((element) => element.path.split('\\').last == file.path.split('\\').last) == -1) {
imgList.add(file);
}
if (p.extension(file.path) == '.mp4' || p.extension(file.path) == '.webm') {
if ((p.extension(file.path) == '.mp4' || p.extension(file.path) == '.webm') && vidList.indexWhere((element) => element.path.split('\\').last == file.path.split('\\').last) == -1) {
vidList.add(file);
}
}
Expand Down Expand Up @@ -908,6 +962,31 @@ Future<void> dragDropModsAddFoldersOnly(context, List<XFile> newModDragDropList,
List<File> imgList = filesList.where((e) => (p.extension(e.path) == '.jpg' || p.extension(e.path) == '.png') && e.parent.path == file.parent.path).toList();
List<File> vidList = filesList.where((e) => (p.extension(e.path) == '.mp4' || p.extension(e.path) == '.webm') && e.parent.path == file.parent.path).toList();

if (imgList.isEmpty || vidList.isEmpty) {
List<String> filePathSplit = file.path.split('$newModPath\\').last.split('\\');
filePathSplit.insert(0, newItemName!);
String fileName = filePathSplit.removeLast();
String tempPath = file.path.split('\\$fileName').first;
for (var folderPath in filePathSplit.reversed) {
List<File> imgVidGet = Directory(tempPath)
.listSync(recursive: false)
.whereType<File>()
.where((e) => p.extension(e.path) == '.jpg' || p.extension(e.path) == '.png' || p.extension(e.path) == '.mp4' || p.extension(e.path) == '.webm')
.toList();
if (imgVidGet.isNotEmpty) {
for (var file in imgVidGet) {
if ((p.extension(file.path) == '.jpg' || p.extension(file.path) == '.png') && imgList.indexWhere((element) => element.path.split('\\').last == file.path.split('\\').last) == -1) {
imgList.add(file);
}
if ((p.extension(file.path) == '.mp4' || p.extension(file.path) == '.webm') && vidList.indexWhere((element) => element.path.split('\\').last == file.path.split('\\').last) == -1) {
vidList.add(file);
}
}
}
tempPath = tempPath.split('\\$folderPath').first;
}
}

ModFile newModFile = ModFile('', newModPath, curItemName, file.path, iceName, iceParents, '', '', getImagesList(imgList), false, true, true, false, vidList);
newModFile.categoryName = matchedCategory.categoryName;
newModFile.categoryPath = matchedCategory.categoryPath;
Expand Down
32 changes: 23 additions & 9 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
super.dispose();
}

void refreshHomePage() {
setState(() {});
}

@override
Widget build(BuildContext context) {
MultiSplitView mainViews = MultiSplitView(
Expand Down Expand Up @@ -352,7 +356,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
child: ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: cateList.length,
itemCount: Provider.of<stateProvider>(context, listen: false).cateListItemCount,
itemBuilder: (context, index) {
return AbsorbPointer(
absorbing: isSearching,
Expand Down Expand Up @@ -700,8 +704,14 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
popupHeight += 24;
}
String stillApplied = stillAppliedList.join('\n');
itemDeleteDialog(context, popupHeight, 'Delete Item', 'Cannot delete "${cateList[index].itemNames[i]}". Unaplly these mods first:\n\n$stillApplied',
false, cateList[index], cateList[index].itemNames[i], []);
itemDeleteDialog(
context,
popupHeight,
'Delete Item',
'Cannot delete "${cateList[index].itemNames[i]}". Unaplly these mods first:\n\n$stillApplied',
false,
cateList[index],
cateList[index].itemNames[i], []);
}
});
}),
Expand Down Expand Up @@ -923,7 +933,8 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
waitDuration: const Duration(seconds: 1),
child: MaterialButton(
onPressed: (() async {
List<List<ModFile>> modListToRemoveFav = await getModFilesByCategory(cateListSearchResult[index].allModFiles, cateListSearchResult[index].itemNames[i]);
List<List<ModFile>> modListToRemoveFav =
await getModFilesByCategory(cateListSearchResult[index].allModFiles, cateListSearchResult[index].itemNames[i]);
for (var element in modListToRemoveFav) {
cateListSearchResult[index] = addOrRemoveFav(cateListSearchResult, element, cateListSearchResult[index], false);
}
Expand Down Expand Up @@ -1724,7 +1735,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
} else if (newSingleItemFormKey.currentState!.validate() && _itemAdderTabcontroller.index == 0) {
isErrorInSingleItemName = false;
isItemAddBtnClicked = true;
dragDropSingleFilesAdd(context, _newSingleItemDragDropList, _singleItemIcon!, selectedCategoryForSingleItem,
dragDropSingleFilesAdd(context, _newSingleItemDragDropList, _singleItemIcon, selectedCategoryForSingleItem,
newSingleItemAddController.text.isEmpty ? null : newSingleItemAddController.text)
.then((_) {
setState(() {
Expand Down Expand Up @@ -1877,6 +1888,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
isPreviewImgsOn = false;
isPreviewVidOn = false;
previewPlayer.pause();
currentImg = 0;
});
}
},
Expand Down Expand Up @@ -2408,8 +2420,8 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
});
} else {
isModAddFolderOnly = true;
dragDropModsAdd(context, _newModToItemDragDropList, modFilesList.first.first.categoryName, modsViewAppBarName, modFilesList.first.first.modPath, _newModToItemIndex,
newModToItemAddController.text.isEmpty ? null : newModToItemAddController.text)
dragDropModsAdd(context, _newModToItemDragDropList, modFilesList.first.first.categoryName, modsViewAppBarName, modFilesList.first.first.modPath,
_newModToItemIndex, newModToItemAddController.text.isEmpty ? null : newModToItemAddController.text)
.then((_) {
setState(() {
//setstate to refresh list
Expand Down Expand Up @@ -2467,13 +2479,14 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
modPreviewImgList = snapshot.data;
//print(modPreviewImgList.toString());
previewImageSliders = modPreviewImgList

.map((item) => Container(
margin: const EdgeInsets.all(2.0),
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
child: Stack(
children: <Widget>[
Image.file(item, fit: BoxFit.cover, width: 1000.0),
Image.file(item),
//Text(modPreviewImgList.toString())
],
)),
Expand All @@ -2482,7 +2495,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
List<Widget> previewImageSlidersBox = [];
for (var element in previewImageSliders) {
previewImageSlidersBox.add(FittedBox(
fit: BoxFit.fitHeight,
fit: BoxFit.contain,
child: element,
));
}
Expand Down Expand Up @@ -2765,6 +2778,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
isPreviewImgsOn = false;
isPreviewVidOn = false;
previewPlayer.pause();
currentImg = 0;
});
}
},
Expand Down
12 changes: 4 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';
import 'package:pso2_mod_manager/data_loading_page.dart';
import 'package:pso2_mod_manager/file_functions.dart';
import 'package:pso2_mod_manager/home_page.dart';
import 'package:pso2_mod_manager/mod_classes.dart';
import 'package:pso2_mod_manager/custom_window_button.dart';
import 'package:pso2_mod_manager/mods_loader.dart';
import 'package:pso2_mod_manager/state_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pso2_mod_manager/popup_handlers.dart';
Expand Down Expand Up @@ -303,8 +305,7 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
waitDuration: const Duration(seconds: 1),
child: MaterialButton(
onPressed: (() {
binDirDialog(context, 'Info', 'Reselecting pso2_bin folder?', true).then((_) {
//RestartWidget.restartApp(context);
binDirDialog(context, 'pso2_bin Path Reselect', 'Current path:\n\'$binDirPath\'\n\nChoose a new path?', true).then((_) {
setState(() {
//setstate
});
Expand All @@ -331,12 +332,7 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
waitDuration: const Duration(seconds: 1),
child: MaterialButton(
onPressed: (() {
mainModManDirDialog(context, 'Mod Manager Path Reselect', 'Select a new path to store your mods?', false).then((_) {
setState(() {
//setstate
RestartWidget.restartApp(context);
});
});
mainModManDirDialog(context, 'Mod Manager Path Reselect', 'Current path:\n\'$mainModDirPath\'\n\nChoose a new path?', true);
}),
child: Row(
children: const [
Expand Down
Loading

0 comments on commit 850fd08

Please sign in to comment.