diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 70463be5c..c2afca1e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,53 +6,53 @@ on: merge_group: jobs: - ios-build: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - with: - ref: dev - - uses: subosito/flutter-action@v2 - with: - # flutter-version: '2.5.2' - channel: 'stable' - - uses: actions/setup-python@v2 - with: - python-version: '3.8' - - name: Preprocess - run: | - # cd lib/server - # wget -q ${{ secrets.SECRET_SALT }} - # wget -q ${{ secrets.SECRET_WSALT }} - # cd ../.. - cat << EOF > lib/server/salt.dart - String getValid(foo) {return foo;} - EOF - cat << EOF > lib/server/wsalt.dart - String getValid(foo) {return foo;} - EOF - python3 preprocess-ios.py - - name: Podfile - run: | - cd ios - rm Podfile.lock - flutter clean - flutter pub get - pod install - pod update - cd .. - - name: Build - run: | - flutter build ios --release --no-codesign - mkdir -p Payload - mv ./build/ios/iphoneos/Runner.app Payload - zip -r -y Payload.zip Payload/Runner.app - mv Payload.zip Payload.ipa - - name: Upload IPA - uses: actions/upload-artifact@v2 - with: - name: ipa-build - path: Payload.ipa + # ios-build: + # runs-on: macos-latest + # steps: + # - uses: actions/checkout@v2 + # with: + # ref: dev + # - uses: subosito/flutter-action@v2 + # with: + # # flutter-version: '2.5.2' + # channel: 'stable' + # - uses: actions/setup-python@v2 + # with: + # python-version: '3.8' + # - name: Preprocess + # run: | + # # cd lib/server + # # wget -q ${{ secrets.SECRET_SALT }} + # # wget -q ${{ secrets.SECRET_WSALT }} + # # cd ../.. + # cat << EOF > lib/server/salt.dart + # String getValid(foo) {return foo;} + # EOF + # cat << EOF > lib/server/wsalt.dart + # String getValid(foo) {return foo;} + # EOF + # python3 preprocess-ios.py + # - name: Podfile + # run: | + # cd ios + # rm Podfile.lock + # flutter clean + # flutter pub get + # pod install + # pod update + # cd .. + # - name: Build + # run: | + # flutter build ios --release --no-codesign + # mkdir -p Payload + # mv ./build/ios/iphoneos/Runner.app Payload + # zip -r -y Payload.zip Payload/Runner.app + # mv Payload.zip Payload.ipa + # - name: Upload IPA + # uses: actions/upload-artifact@v2 + # with: + # name: ipa-build + # path: Payload.ipa # https://github.com/AppImageCrafters/appimage-builder-flutter-example/blob/main/.github/workflows/appimage.yml linux-build: @@ -103,41 +103,41 @@ jobs: # files: './*.AppImage*' # repo_token: ${{ secrets.GITHUB_TOKEN }} - android-build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: dev - - uses: actions/setup-java@v1 - with: - java-version: '12.x' - - uses: subosito/flutter-action@v1 - with: - # flutter-version: '2.5.2' - channel: 'stable' - - uses: actions/setup-python@v2 - with: - python-version: '3.8' - - name: Preprocess - run: | - # cd lib/server - # wget -q ${{ secrets.SECRET_SALT }} - # wget -q ${{ secrets.SECRET_WSALT }} - # cd ../.. - cat << EOF > lib/server/salt.dart - String getValid(foo) {return foo;} - EOF - cat << EOF > lib/server/wsalt.dart - String getValid(foo) {return foo;} - EOF - python3 preprocess-android.py - - name: Build - run: | - flutter clean - flutter build apk --release - - name: Upload APK - uses: actions/upload-artifact@v2 - with: - name: apk-build - path: ./build/app/outputs/apk/release/app-release.apk + # android-build: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v2 + # with: + # ref: dev + # - uses: actions/setup-java@v1 + # with: + # java-version: '12.x' + # - uses: subosito/flutter-action@v1 + # with: + # # flutter-version: '2.5.2' + # channel: 'stable' + # - uses: actions/setup-python@v2 + # with: + # python-version: '3.8' + # - name: Preprocess + # run: | + # # cd lib/server + # # wget -q ${{ secrets.SECRET_SALT }} + # # wget -q ${{ secrets.SECRET_WSALT }} + # # cd ../.. + # cat << EOF > lib/server/salt.dart + # String getValid(foo) {return foo;} + # EOF + # cat << EOF > lib/server/wsalt.dart + # String getValid(foo) {return foo;} + # EOF + # python3 preprocess-android.py + # - name: Build + # run: | + # flutter clean + # flutter build apk --release + # - name: Upload APK + # uses: actions/upload-artifact@v2 + # with: + # name: apk-build + # path: ./build/app/outputs/apk/release/app-release.apk diff --git a/AppImageBuilder.yml b/AppImageBuilder.yml index eb822fc01..f5ad3da2a 100644 --- a/AppImageBuilder.yml +++ b/AppImageBuilder.yml @@ -2,7 +2,7 @@ version: 1 script: - rm -rf AppDir || true - - cp -r build/linux/x64/release/bundle AppDir + - cp -r build/linux/x64/release AppDir - mkdir -p AppDir/usr/share/icons/hicolor/64x64/apps/ - cp assets/images/logo.png AppDir/usr/share/icons/hicolor/64x64/apps/ AppDir: @@ -12,7 +12,7 @@ AppDir: name: Violet icon: logo version: latest - exec: violet + exec: ./bundle/violet exec_args: $@ apt: arch: amd64 @@ -37,8 +37,9 @@ AppDir: - ubuntu-mono files: include: - - lib/*.so - - data + - ./* + - bundle/lib/*.so + - bundle/data exclude: - usr/share/man - usr/share/doc/*/README.* diff --git a/lib/checker/checker.dart b/lib/checker/checker.dart index b0b208973..31e31be91 100644 --- a/lib/checker/checker.dart +++ b/lib/checker/checker.dart @@ -106,8 +106,20 @@ class VioletChecker { // // 0. get database path // - var dir = await getApplicationDocumentsDirectory(); - var dbPath = '${dir.path}/user.db'; + var dir; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + dir = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + dir = '${home}/.violet'; + } + var dbPath = '${dir}/user.db'; // // 1. check file exists diff --git a/lib/component/hitomi/hitomi.dart b/lib/component/hitomi/hitomi.dart index 5284e8a88..e512cc974 100644 --- a/lib/component/hitomi/hitomi.dart +++ b/lib/component/hitomi/hitomi.dart @@ -10,6 +10,7 @@ import 'package:tuple/tuple.dart'; import 'package:violet/algorithm/distance.dart'; import 'package:violet/component/hitomi/displayed_tag.dart'; import 'package:violet/component/hitomi/tag_translate.dart'; +import 'package:violet/log/log.dart'; import 'package:violet/script/script_manager.dart'; import 'package:violet/settings/settings.dart'; import 'package:violet/variables.dart'; @@ -18,6 +19,7 @@ class HitomiManager { // [Image List], [Big Thumbnail List (Perhaps only two are valid.)], [Small Thubmnail List] static Future, List, List>> getImageList( String id) async { + Logger.info('[runHitomiGetImageList] id = ${id}'); final result = await ScriptManager.runHitomiGetImageList(int.parse(id)); if (result != null) return result; return const Tuple3, List, List>( @@ -27,8 +29,18 @@ class HitomiManager { static int? getArticleCount(String classification, String name) { if (tagmap == null) { final subdir = Platform.isAndroid ? '/data' : ''; - final path = - File('${Variables.applicationDocumentsDirectory}$subdir/index.json'); + late final path; + if(Platform.isAndroid || Platform.isIOS){ + path = File('${Variables.applicationDocumentsDirectory}$subdir/index.json'); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + path = File('${home}/.violet$subdir/index.json'); + } final text = path.readAsStringSync(); tagmap = jsonDecode(text); } @@ -38,8 +50,18 @@ class HitomiManager { static void reloadIndex() { final subdir = Platform.isAndroid ? '/data' : ''; - final path = - File('${Variables.applicationDocumentsDirectory}$subdir/index.json'); + late final path; + if(Platform.isAndroid || Platform.isIOS){ + path = File('${Variables.applicationDocumentsDirectory}$subdir/index.json'); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + path = File('${home}/.violet$subdir/index.json'); + } final text = path.readAsStringSync(); tagmap = jsonDecode(text); } @@ -81,8 +103,21 @@ class HitomiManager { tagmap = jsonDecode(await file.readAsString()); } else { final subdir = Platform.isAndroid ? '/data' : ''; - final directory = await getApplicationDocumentsDirectory(); - final path = File('${directory.path}$subdir/index.json'); + late final directory; + late final path; + if(Platform.isAndroid || Platform.isIOS){ + directory = await getApplicationDocumentsDirectory(); + path = File('${directory.path}$subdir/index.json'); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + path = File('${directory}$subdir/index.json'); + } final text = path.readAsStringSync(); tagmap = jsonDecode(text); } diff --git a/lib/component/hitomi/indexs.dart b/lib/component/hitomi/indexs.dart index 03a529547..bdb488a5f 100644 --- a/lib/component/hitomi/indexs.dart +++ b/lib/component/hitomi/indexs.dart @@ -40,32 +40,44 @@ class HitomiIndexs { static late Map relatedTag; static Future init() async { - final directory = await getApplicationDocumentsDirectory(); + late final directory; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + directory = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + } final subdir = Platform.isAndroid ? '/data' : ''; // No data on first run. - final path2 = File('${directory.path}$subdir/tag-artist.json'); + final path2 = File('${directory}$subdir/tag-artist.json'); if (!await path2.exists()) return; tagArtist = jsonDecode(await path2.readAsString()); - final path3 = File('${directory.path}$subdir/tag-group.json'); + final path3 = File('${directory}$subdir/tag-group.json'); tagGroup = jsonDecode(await path3.readAsString()); - final path4 = File('${directory.path}$subdir/tag-index.json'); + final path4 = File('${directory}$subdir/tag-index.json'); tagIndex = jsonDecode(await path4.readAsString()); - final path5 = File('${directory.path}$subdir/tag-uploader.json'); + final path5 = File('${directory}$subdir/tag-uploader.json'); tagUploader = jsonDecode(await path5.readAsString()); try { - final path6 = File('${directory.path}$subdir/tag-series.json'); + final path6 = File('${directory}$subdir/tag-series.json'); tagSeries = jsonDecode(await path6.readAsString()); - final path7 = File('${directory.path}$subdir/tag-character.json'); + final path7 = File('${directory}$subdir/tag-character.json'); tagCharacter = jsonDecode(await path7.readAsString()); - final path8 = File('${directory.path}$subdir/character-series.json'); + final path8 = File('${directory}$subdir/character-series.json'); characterSeries = jsonDecode(await path8.readAsString()); - final path9 = File('${directory.path}$subdir/series-character.json'); + final path9 = File('${directory}$subdir/series-character.json'); seriesCharacter = jsonDecode(await path9.readAsString()); - final path10 = File('${directory.path}$subdir/character-character.json'); + final path10 = File('${directory}$subdir/character-character.json'); characterCharacter = jsonDecode(await path10.readAsString()); - final path11 = File('${directory.path}$subdir/series-series.json'); + final path11 = File('${directory}$subdir/series-series.json'); seriesSeries = jsonDecode(await path11.readAsString()); } catch (e, st) { Logger.error('[Hitomi-Indexs] E: $e\n' diff --git a/lib/component/hitomi/series_finder.dart b/lib/component/hitomi/series_finder.dart index aa6e7165b..7e23aff91 100644 --- a/lib/component/hitomi/series_finder.dart +++ b/lib/component/hitomi/series_finder.dart @@ -13,8 +13,21 @@ import 'package:violet/database/query.dart'; class SeriesFinder { static Future doFind1() async { final subdir = Platform.isAndroid ? '/data' : ''; - final directory = await getApplicationDocumentsDirectory(); - final path = File('${directory.path}$subdir/index.json'); + late final directory; + late final path; + if(Platform.isAndroid || Platform.isIOS){ + directory = await getApplicationDocumentsDirectory(); + path = File('${directory.path}$subdir/index.json'); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + path = '${directory}$subdir/index.json'; + } final text = path.readAsStringSync(); final tagmap = jsonDecode(text); final artists = tagmap['artist'] as Map; diff --git a/lib/log/act_log.dart b/lib/log/act_log.dart index 70eb1c324..81a94cd1e 100644 --- a/lib/log/act_log.dart +++ b/lib/log/act_log.dart @@ -109,8 +109,20 @@ class ActLogger { if (Platform.environment.containsKey('FLUTTER_TEST')) { logFile = File('act-log.txt'); } else { - final dir = await getApplicationDocumentsDirectory(); - logFile = File(join(dir.path, 'act-log.txt')); + late final dir; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + dir = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + dir = '${home}/.violet'; + } + logFile = File(join(dir, 'act-log.txt')); } if (!await logFile.exists()) { @@ -138,10 +150,22 @@ class ActLogger { } static Future exportLog() async { - final ext = Platform.isIOS + late final ext; + if(Platform.isAndroid || Platform.isIOS){ + var d = Platform.isIOS ? await getApplicationSupportDirectory() : await getExternalStorageDirectory(); - final extpath = '${ext!.path}/act-log.txt'; + ext = d!.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + key = value; + } + }); + ext = '${home}/.violet'; + } + final extpath = '${ext}/act-log.txt'; await logFile.copy(extpath); } } diff --git a/lib/log/log.dart b/lib/log/log.dart index d5bb7a2dd..4c20cf7e0 100644 --- a/lib/log/log.dart +++ b/lib/log/log.dart @@ -48,8 +48,19 @@ class Logger { if (Platform.environment.containsKey('FLUTTER_TEST')) { logFile = File('log.txt'); } else { - final dir = await getApplicationDocumentsDirectory(); - logFile = File(join(dir.path, 'log.txt')); + if(Platform.isAndroid || Platform.isIOS){ + final dir = await getApplicationDocumentsDirectory(); + logFile = File(join(dir.path, 'log.txt')); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + final dir = '${home}/.violet'; + logFile = File(join(dir, 'log.txt')); + } } if (!await logFile.exists()) { @@ -62,6 +73,7 @@ class Logger { if (!Platform.environment.containsKey('FLUTTER_TEST')) { await lock.synchronized(() async { + await init(); await logFile.writeAsString('[${DateTime.now().toUtc()}] $msg\n', mode: FileMode.append); }); diff --git a/lib/pages/database_download/database_download_page.dart b/lib/pages/database_download/database_download_page.dart index c5e3ab443..8c49812aa 100644 --- a/lib/pages/database_download/database_download_page.dart +++ b/lib/pages/database_download/database_download_page.dart @@ -74,9 +74,22 @@ class DataBaseDownloadPageState extends State { dbPath = '${home}/.violet/data.db'; } if (await File(dbPath).exists()) await File(dbPath).delete(); - var dir = await getApplicationDocumentsDirectory(); - if (await Directory('${dir.path}/data').exists()) { - await Directory('${dir.path}/data').delete(recursive: true); + var dir; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + dir = d.path; + } + if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + dir = '${home}/.violet'; + } + if (await Directory('${dir}/data').exists()) { + await Directory('${dir}/data').delete(recursive: true); } } } catch (e, st) { @@ -662,30 +675,42 @@ class DataBaseDownloadPageState extends State { 'class': classes, }; - final directory = await getApplicationDocumentsDirectory(); - final path1 = File('${directory.path}/index.json'); + late final directory; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + directory = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + } + final path1 = File('${directory}/index.json'); path1.writeAsString(jsonEncode(index)); - final path2 = File('${directory.path}/tag-artist.json'); + final path2 = File('${directory}/tag-artist.json'); path2.writeAsString(jsonEncode(tagArtist)); - final path3 = File('${directory.path}/tag-group.json'); + final path3 = File('${directory}/tag-group.json'); path3.writeAsString(jsonEncode(tagGroup)); - final path4 = File('${directory.path}/tag-index.json'); + final path4 = File('${directory}/tag-index.json'); path4.writeAsString(jsonEncode(tagIndex)); - final path5 = File('${directory.path}/tag-uploader.json'); + final path5 = File('${directory}/tag-uploader.json'); path5.writeAsString(jsonEncode(tagUploader)); - final path6 = File('${directory.path}/tag-series.json'); + final path6 = File('${directory}/tag-series.json'); path6.writeAsString(jsonEncode(tagSeries)); - final path7 = File('${directory.path}/tag-character.json'); + final path7 = File('${directory}/tag-character.json'); path7.writeAsString(jsonEncode(tagCharacter)); - final path8 = File('${directory.path}/character-series.json'); + final path8 = File('${directory}/character-series.json'); path8.writeAsString(jsonEncode(characterSeries)); - final path9 = File('${directory.path}/series-character.json'); + final path9 = File('${directory}/series-character.json'); path9.writeAsString(jsonEncode(seriesCharacter)); - final path10 = File('${directory.path}/character-character.json'); + final path10 = File('${directory}/character-character.json'); path10.writeAsString(jsonEncode(characterCharacter)); - final path11 = File('${directory.path}/series-series.json'); + final path11 = File('${directory}/series-series.json'); path11.writeAsString(jsonEncode(seriesSeries)); setState(() { diff --git a/lib/pages/download/download_page.dart b/lib/pages/download/download_page.dart index a32a12b03..6e82d6ec5 100644 --- a/lib/pages/download/download_page.dart +++ b/lib/pages/download/download_page.dart @@ -124,7 +124,18 @@ class _DownloadPageState extends ThemeSwitchableState /// to /// /var/mobile/Containers/Data/Application//Documents - final newPath = (await getApplicationDocumentsDirectory()).path; + late final newPath; + if(Platform.isAndroid || Platform.isIOS){ + newPath = (await getApplicationDocumentsDirectory()).path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + newPath = '${home}/.violet'; + } else { newPath = ''; } for (var item in items) { if (item.files() == null) continue; diff --git a/lib/pages/main/info/lab/bookmark/bookmarks.dart b/lib/pages/main/info/lab/bookmark/bookmarks.dart index 4b823683e..a3d69bb9a 100644 --- a/lib/pages/main/info/lab/bookmark/bookmarks.dart +++ b/lib/pages/main/info/lab/bookmark/bookmarks.dart @@ -1,6 +1,8 @@ // This source code is a part of Project Violet. // Copyright (C) 2020-2023. violet-team. Licensed under the Apache-2.0 License. +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; import 'package:sqflite/sqflite.dart'; @@ -170,8 +172,21 @@ class _BookmarkPageState extends State { Colors.black, DateTime.parse(data.datetime())); - var dir = await getApplicationDocumentsDirectory(); - var dbraw = await openDatabase('${dir.path}/user.db'); + + var dir; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + dir = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + dir = '${home}/.violet'; + } + var dbraw = await openDatabase('${dir}/user.db'); await dbraw.transaction((txn) async { final batch = txn.batch(); for (var article in articles) { diff --git a/lib/pages/main/main_page.dart b/lib/pages/main/main_page.dart index d363fc664..431d154a7 100644 --- a/lib/pages/main/main_page.dart +++ b/lib/pages/main/main_page.dart @@ -534,12 +534,24 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { return; } - var dir = await getApplicationDocumentsDirectory(); + var dir; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + dir = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + dir = '${home}/.violet'; + } try { - await ((await openDatabase('${dir.path}/data/data.db')).close()); - await deleteDatabase('${dir.path}/data/data.db'); - await Directory('${dir.path}/data').delete(recursive: true); + await ((await openDatabase('${dir}/data/data.db')).close()); + await deleteDatabase('${dir}/data/data.db'); + await Directory('${dir}/data').delete(recursive: true); } catch (_) {} setState(() { @@ -554,8 +566,21 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { ))) .then((value) async { HitomiIndexs.init(); - final directory = await getApplicationDocumentsDirectory(); - final path = File('${directory.path}/data/index.json'); + late final directory; + late final path; + if(Platform.isAndroid || Platform.isIOS){ + directory = await getApplicationDocumentsDirectory(); + path = File('${directory.path}/data/index.json'); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + path = File('${directory}/index.json'); + } final text = path.readAsStringSync(); HitomiManager.tagmap = jsonDecode(text); await DataBaseManager.reloadInstance(); diff --git a/lib/pages/settings/restore_bookmark.dart b/lib/pages/settings/restore_bookmark.dart index 4825cdbde..9c2fd0f45 100644 --- a/lib/pages/settings/restore_bookmark.dart +++ b/lib/pages/settings/restore_bookmark.dart @@ -1,6 +1,8 @@ // This source code is a part of Project Violet. // Copyright (C) 2020-2023. violet-team. Licensed under the Apache-2.0 License. +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:path_provider/path_provider.dart'; @@ -58,8 +60,19 @@ class _RestoreBookmarkPageState extends State { } // 북마크 작품 처리 - var dir = await getApplicationDocumentsDirectory(); - var dbraw = await openDatabase('${dir.path}/user.db'); + var dir; + if(Platform.isAndroid || Platform.isIOS){ + dir = await getApplicationDocumentsDirectory(); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + dir = '${home}/.violet'; + } + var dbraw = await openDatabase('${dir}/user.db'); await dbraw.transaction((txn) async { final batch = txn.batch(); for (var article in articles) { diff --git a/lib/pages/settings/settings_page.dart b/lib/pages/settings/settings_page.dart index 9c70e3c8c..adf2cfb71 100644 --- a/lib/pages/settings/settings_page.dart +++ b/lib/pages/settings/settings_page.dart @@ -1231,12 +1231,24 @@ class _SettingsPageState extends State return; } - var dir = await getApplicationDocumentsDirectory(); + var dir; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + dir = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + dir = '${home}/.violet'; + } try { - await ((await openDatabase('${dir.path}/data/data.db')) + await ((await openDatabase('${dir}/data/data.db')) .close()); - await deleteDatabase('${dir.path}/data/data.db'); - await Directory('${dir.path}/data') + await deleteDatabase('${dir}/data/data.db'); + await Directory('${dir}/data') .delete(recursive: true); } catch (_) {} @@ -1249,8 +1261,19 @@ class _SettingsPageState extends State .then( (value) async { HitomiIndexs.init(); - final directory = - await getApplicationDocumentsDirectory(); + late final directory; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + directory = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + } final path = File('${directory.path}/data/index.json'); final text = path.readAsStringSync(); HitomiManager.tagmap = jsonDecode(text); diff --git a/lib/pages/settings/tag_rebuild_page.dart b/lib/pages/settings/tag_rebuild_page.dart index 7e5ab9b10..4b24dd75b 100644 --- a/lib/pages/settings/tag_rebuild_page.dart +++ b/lib/pages/settings/tag_rebuild_page.dart @@ -353,42 +353,55 @@ class _TagRebuildPageState extends State { }; final subdir = Platform.isAndroid ? '/data' : ''; - final directory = await getApplicationDocumentsDirectory(); - final path1 = File('${directory.path}$subdir/index.json'); + + late final directory; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + directory = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + } + final path1 = File('${directory}$subdir/index.json'); if (path1.existsSync()) path1.deleteSync(); path1.writeAsString(jsonEncode(index)); print(index); - final path2 = File('${directory.path}$subdir/tag-artist.json'); + final path2 = File('${directory}$subdir/tag-artist.json'); if (path2.existsSync()) path2.deleteSync(); path2.writeAsString(jsonEncode(tagArtist)); - final path3 = File('${directory.path}$subdir/tag-group.json'); + final path3 = File('${directory}$subdir/tag-group.json'); if (path3.existsSync()) path3.deleteSync(); path3.writeAsString(jsonEncode(tagGroup)); - final path4 = File('${directory.path}$subdir/tag-index.json'); + final path4 = File('${directory}$subdir/tag-index.json'); if (path4.existsSync()) path4.deleteSync(); path4.writeAsString(jsonEncode(tagIndex)); - final path5 = File('${directory.path}$subdir/tag-uploader.json'); + final path5 = File('${directory}$subdir/tag-uploader.json'); if (path5.existsSync()) path5.deleteSync(); path5.writeAsString(jsonEncode(tagUploader)); - final path6 = File('${directory.path}$subdir/tag-series.json'); + final path6 = File('${directory}$subdir/tag-series.json'); if (path6.existsSync()) path6.deleteSync(); path6.writeAsString(jsonEncode(tagSeries)); - final path7 = File('${directory.path}$subdir/tag-character.json'); + final path7 = File('${directory}$subdir/tag-character.json'); if (path7.existsSync()) path7.deleteSync(); path7.writeAsString(jsonEncode(tagCharacter)); - final path8 = File('${directory.path}$subdir/character-series.json'); + final path8 = File('${directory}$subdir/character-series.json'); if (path8.existsSync()) path8.deleteSync(); path8.writeAsString(jsonEncode(characterSeries)); - final path9 = File('${directory.path}$subdir/series-character.json'); + final path9 = File('${directory}$subdir/series-character.json'); if (path9.existsSync()) path9.deleteSync(); path9.writeAsString(jsonEncode(seriesCharacter)); final path10 = - File('${directory.path}$subdir/character-character.json'); + File('${directory}$subdir/character-character.json'); if (path10.existsSync()) path10.deleteSync(); path10.writeAsString(jsonEncode(characterCharacter)); - final path11 = File('${directory.path}$subdir/series-series.json'); + final path11 = File('${directory}$subdir/series-series.json'); if (path11.existsSync()) path11.deleteSync(); path11.writeAsString(jsonEncode(seriesSeries)); diff --git a/lib/pages/splash/splash_page.dart b/lib/pages/splash/splash_page.dart index 323230902..8d433e6d5 100644 --- a/lib/pages/splash/splash_page.dart +++ b/lib/pages/splash/splash_page.dart @@ -569,11 +569,23 @@ class _SplashPageState extends State { } } if (widget.switching) { - var dir = await getApplicationDocumentsDirectory(); + var dir; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + dir = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + dir = '${home}/.violet'; + } try { - await ((await openDatabase('${dir.path}/data/data.db')).close()); - await deleteDatabase('${dir.path}/data/data.db'); - await Directory('${dir.path}/data').delete(recursive: true); + await ((await openDatabase('${dir}/data/data.db')).close()); + await deleteDatabase('${dir}/data/data.db'); + await Directory('${dir}/data').delete(recursive: true); } catch (_) {} } print(Translations.of(context).dbLanguageCode); diff --git a/lib/script/script_manager.dart b/lib/script/script_manager.dart index 7fe56d375..9ebdd7ec1 100644 --- a/lib/script/script_manager.dart +++ b/lib/script/script_manager.dart @@ -119,6 +119,9 @@ class ScriptManager { if (_scriptCache == null) return null; try { + if(_runtime == null){ + _initRuntime(); + } var downloadUrl = _runtime.evaluate("create_download_url('$id')").stringResult; var headers = await runHitomiGetHeaderContent(id.toString());