Skip to content

Commit

Permalink
Merge pull request #11 from KizKizz/backend-rework
Browse files Browse the repository at this point in the history
Backend rework
  • Loading branch information
KizKizz committed Jun 29, 2022
2 parents 8133a2c + 01fec56 commit 9b3317c
Show file tree
Hide file tree
Showing 8 changed files with 652 additions and 249 deletions.
187 changes: 141 additions & 46 deletions lib/file_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,70 +316,58 @@ void modsRemover(List<ModFile> modsList) {
}

// New File Adders
Future<void> dragDropSingleFilesAdd(context, List<XFile> newItemDragDropList, String? selectedCategoryName, String? newItemName) async {
Future<void> dragDropSingleFilesAdd(context, List<XFile> newItemDragDropList, XFile? itemIcon, String? selectedCategoryName, String? newItemName) async {
final categoryName = selectedCategoryName;
final catePath = cateList.firstWhere((element) => element.categoryName == categoryName).categoryPath;

bool isFilesFound = false;
for (var xFile in newItemDragDropList) {
await Future(
() {
if (!Directory(xFile.path).existsSync()) {
String newPath = catePath;
final fileParent = File(xFile.path).parent.path.split('\\').last;
if (newItemName != null) {
//Item suffix
if (categoryName == 'Basewears' && !xFile.name.contains('[Ba]')) {
newPath += '\\$newItemName [Ba]\\$fileParent\\${xFile.name}';
} else if (categoryName == 'Innerwears' && !xFile.name.contains('[In]')) {
newPath += '\\$newItemName [In]\\$fileParent\\${xFile.name}';
} else if (categoryName == 'Outerwears' && !xFile.name.contains('[Ou]')) {
newPath += '\\$newItemName [Ou]\\$fileParent\\${xFile.name}';
} else if (categoryName == 'Setwears' && !xFile.name.contains('[Se]')) {
newPath += '\\$newItemName [Se]\\$fileParent\\${xFile.name}';
} else {
newPath += '\\$newItemName\\$fileParent\\${xFile.name}';
}
}
File(newPath).createSync(recursive: true);
File(xFile.path).copySync(newPath);
} else {
if (!Directory(xFile.path).existsSync()) {
isFilesFound = true;
break;
}
}

if (!isFilesFound) {
for (var xFile in newItemDragDropList) {
await Future(
() {
final files = Directory(xFile.path).listSync(recursive: true).whereType<File>();
if (files.isNotEmpty) {
for (var file in files) {
final fileTailPath = file.path.split('${xFile.name}\\').last.split('\\');
String newPath = catePath;
final fileParent = File(xFile.path).parent.path.split('\\').last;
//final fileParent = File(xFile.path).parent.path.split('\\').last;
if (fileTailPath.indexWhere((e) => e == 'win32' || e == 'win32_na' || e == 'win32reboot' || e == 'win32reboot_na') != -1) {
fileTailPath.removeRange(fileTailPath.indexWhere((e) => e == 'win32' || e == 'win32_na' || e == 'win32reboot' || e == 'win32reboot_na'), fileTailPath.indexOf(fileTailPath.last));
String finalTailPath = fileTailPath.join('\\');
if (newItemName != null) {
//Item suffix
if (categoryName == 'Basewears' && !xFile.name.contains('[Ba]')) {
newPath += '\\$newItemName [Ba]\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName [Ba]\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Innerwears' && !xFile.name.contains('[In]')) {
newPath += '\\$newItemName [In]\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName [In]\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Outerwears' && !xFile.name.contains('[Ou]')) {
newPath += '\\$newItemName [Ou]\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName [Ou]\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Setwears' && !xFile.name.contains('[Se]')) {
newPath += '\\$newItemName [Se]\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName [Se]\\${xFile.name}\\$finalTailPath';
} else {
newPath += '\\$newItemName\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName\\${xFile.name}\\$finalTailPath';
}
}
} else {
String finalTailPath = fileTailPath.join('\\');
if (newItemName != null) {
//Item suffix
if (categoryName == 'Basewears' && !xFile.name.contains('[Ba]')) {
newPath += '\\$newItemName [Ba]\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName [Ba]\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Innerwears' && !xFile.name.contains('[In]')) {
newPath += '\\$newItemName [In]\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName [In]\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Outerwears' && !xFile.name.contains('[Ou]')) {
newPath += '\\$newItemName [Ou]\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName [Ou]\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Setwears' && !xFile.name.contains('[Se]')) {
newPath += '\\$newItemName [Se]\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName [Se]\\${xFile.name}\\$finalTailPath';
} else {
newPath += '\\$newItemName\\$fileParent\\${xFile.name}\\$finalTailPath';
newPath += '\\$newItemName\\${xFile.name}\\$finalTailPath';
}
}
}
Expand All @@ -388,10 +376,84 @@ Future<void> dragDropSingleFilesAdd(context, List<XFile> newItemDragDropList, St
File(file.path).copySync(newPath);
}
}
}
},
);
Provider.of<stateProvider>(context, listen: false).singleItemsDropAddRemoveFirst();
},
);
Provider.of<stateProvider>(context, listen: false).singleItemsDropAddRemoveFirst();
}
} else {
for (var xFile in newItemDragDropList) {
await Future(
() {
if (!Directory(xFile.path).existsSync()) {
String newPath = catePath;
final fileParent = File(xFile.path).parent.path.split('\\').last;
if (newItemName != null) {
//Item suffix
if (categoryName == 'Basewears' && !xFile.name.contains('[Ba]')) {
newPath += '\\$newItemName [Ba]\\$fileParent\\${xFile.name}';
} else if (categoryName == 'Innerwears' && !xFile.name.contains('[In]')) {
newPath += '\\$newItemName [In]\\$fileParent\\${xFile.name}';
} else if (categoryName == 'Outerwears' && !xFile.name.contains('[Ou]')) {
newPath += '\\$newItemName [Ou]\\$fileParent\\${xFile.name}';
} else if (categoryName == 'Setwears' && !xFile.name.contains('[Se]')) {
newPath += '\\$newItemName [Se]\\$fileParent\\${xFile.name}';
} else {
newPath += '\\$newItemName\\$fileParent\\${xFile.name}';
}
}
File(newPath).createSync(recursive: true);
File(xFile.path).copySync(newPath);
} else {
final files = Directory(xFile.path).listSync(recursive: true).whereType<File>();
if (files.isNotEmpty) {
for (var file in files) {
final fileTailPath = file.path.split('${xFile.name}\\').last.split('\\');
String newPath = catePath;
final fileParent = File(xFile.path).parent.path.split('\\').last;
if (fileTailPath.indexWhere((e) => e == 'win32' || e == 'win32_na' || e == 'win32reboot' || e == 'win32reboot_na') != -1) {
fileTailPath.removeRange(fileTailPath.indexWhere((e) => e == 'win32' || e == 'win32_na' || e == 'win32reboot' || e == 'win32reboot_na'), fileTailPath.indexOf(fileTailPath.last));
String finalTailPath = fileTailPath.join('\\');
if (newItemName != null) {
//Item suffix
if (categoryName == 'Basewears' && !xFile.name.contains('[Ba]')) {
newPath += '\\$newItemName [Ba]\\$fileParent\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Innerwears' && !xFile.name.contains('[In]')) {
newPath += '\\$newItemName [In]\\$fileParent\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Outerwears' && !xFile.name.contains('[Ou]')) {
newPath += '\\$newItemName [Ou]\\$fileParent\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Setwears' && !xFile.name.contains('[Se]')) {
newPath += '\\$newItemName [Se]\\$fileParent\\${xFile.name}\\$finalTailPath';
} else {
newPath += '\\$newItemName\\$fileParent\\${xFile.name}\\$finalTailPath';
}
}
} else {
String finalTailPath = fileTailPath.join('\\');
if (newItemName != null) {
//Item suffix
if (categoryName == 'Basewears' && !xFile.name.contains('[Ba]')) {
newPath += '\\$newItemName [Ba]\\$fileParent\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Innerwears' && !xFile.name.contains('[In]')) {
newPath += '\\$newItemName [In]\\$fileParent\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Outerwears' && !xFile.name.contains('[Ou]')) {
newPath += '\\$newItemName [Ou]\\$fileParent\\${xFile.name}\\$finalTailPath';
} else if (categoryName == 'Setwears' && !xFile.name.contains('[Se]')) {
newPath += '\\$newItemName [Se]\\$fileParent\\${xFile.name}\\$finalTailPath';
} else {
newPath += '\\$newItemName\\$fileParent\\${xFile.name}\\$finalTailPath';
}
}
}

File(newPath).createSync(recursive: true);
File(file.path).copySync(newPath);
}
}
}
},
);
Provider.of<stateProvider>(context, listen: false).singleItemsDropAddRemoveFirst();
}
}

String modName = '';
Expand Down Expand Up @@ -422,6 +484,11 @@ Future<void> dragDropSingleFilesAdd(context, List<XFile> newItemDragDropList, St
}
}

if (itemIcon != null) {
File('$newItemPath\\${itemIcon.name}').createSync(recursive: true);
File(itemIcon.path).copySync('$newItemPath\\${itemIcon.name}');
}

//Add to list
List<ModFile> newModList = [];
final filesList = Directory(newItemPath).listSync(recursive: true).whereType<File>();
Expand Down Expand Up @@ -455,9 +522,12 @@ Future<void> dragDropSingleFilesAdd(context, List<XFile> newItemDragDropList, St

//Update Cate list
final newModRoot = Directory(newItemPath).listSync(recursive: false).whereType<File>();
final thumbnails = newModRoot.where((e) => p.extension(e.path) == '.jpg' || p.extension(e.path) == '.png').toList();
Iterable<File> thumbnails = newModRoot.where((e) => p.extension(e.path) == '.jpg' || p.extension(e.path) == '.png');
List<File> icons = [];
if (thumbnails.isEmpty) {
thumbnails.add(File('assets/img/placeholdersquare.png'));
icons.add(File('assets/img/placeholdersquare.png'));
} else {
icons.addAll(thumbnails);
}
final selectedCategory = cateList.firstWhere((element) => element.categoryName == categoryName);
if (selectedCategory.itemNames.indexWhere((element) => element == modName) == -1) {
Expand All @@ -472,10 +542,10 @@ Future<void> dragDropSingleFilesAdd(context, List<XFile> newItemDragDropList, St
if (cate.itemNames.indexWhere((e) => e == modName) != -1) {
int index = 0;
if (cate.itemNames.length > 1) {
index = cate.itemNames.indexOf(newItemName.toString());
index = cate.itemNames.indexOf(modName.toString());
}
cate.allModFiles.addAll(newModList);
cate.imageIcons.add(thumbnails);
cate.imageIcons.insert(index, icons);
cate.numOfMods.add(0);
cate.numOfMods[index] = numOfMods;
cate.numOfItems++;
Expand Down Expand Up @@ -685,13 +755,13 @@ Future<void> dragDropFilesAdd(context, List<XFile> newItemDragDropList, String?
}

// New Mod Adders
Future<void> dragDropModsAdd(context, List<XFile> newModDragDropList, String curItemName, String itemPath, int index, String? newItemName) async {
Future<void> dragDropModsAdd(context, List<XFile> newModDragDropList, String curCate, String curItemName, String itemPath, int index, String? newItemName) async {
for (var xFile in newModDragDropList) {
await Future(
() {
if (!Directory(xFile.path).existsSync()) {
String newPath = itemPath;
final fileParent = File(xFile.path).parent.path.split('\\').last;
//final fileParent = File(xFile.path).parent.path.split('\\').last;
if (newItemName != null) {
//Item suffix
newPath += '\\$newItemName\\${xFile.name}';
Expand Down Expand Up @@ -732,7 +802,7 @@ Future<void> dragDropModsAdd(context, List<XFile> newModDragDropList, String cur

//Add to list
List<ModFile> newMods = [];
final matchedCategory = cateList.firstWhere((element) => element.itemNames.indexWhere((e) => e == curItemName) != -1);
final matchedCategory = cateList.firstWhere((element) => element.categoryName == curCate);
final filesList = Directory(newModPath).listSync(recursive: true).whereType<File>();
List<String> parentsList = [];
for (var file in filesList) {
Expand All @@ -742,6 +812,31 @@ Future<void> dragDropModsAdd(context, List<XFile> newModDragDropList, String cur
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.add(file);
}
if (p.extension(file.path) == '.mp4' || p.extension(file.path) == '.webm') {
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
Loading

0 comments on commit 9b3317c

Please sign in to comment.