Skip to content

Commit

Permalink
Fix some path
Browse files Browse the repository at this point in the history
  • Loading branch information
TaYaKi71751 committed Dec 11, 2023
1 parent b4a33c8 commit 07f0e83
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 75 deletions.
16 changes: 14 additions & 2 deletions lib/checker/checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 39 additions & 6 deletions lib/component/hitomi/hitomi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,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);
}
Expand All @@ -38,8 +48,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);
}
Expand Down Expand Up @@ -81,8 +101,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);
}
Expand Down
34 changes: 23 additions & 11 deletions lib/component/hitomi/indexs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,44 @@ class HitomiIndexs {
static late Map<String, dynamic> relatedTag;

static Future<void> 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'
Expand Down
17 changes: 15 additions & 2 deletions lib/component/hitomi/series_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,21 @@ import 'package:violet/database/query.dart';
class SeriesFinder {
static Future<void> 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<String, dynamic>;
Expand Down
32 changes: 28 additions & 4 deletions lib/log/act_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -138,10 +150,22 @@ class ActLogger {
}

static Future<void> 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);
}
}
16 changes: 14 additions & 2 deletions lib/log/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
});
Expand Down
55 changes: 40 additions & 15 deletions lib/pages/database_download/database_download_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,22 @@ class DataBaseDownloadPageState extends State<DataBaseDownloadPage> {
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) {
Expand Down Expand Up @@ -662,30 +675,42 @@ class DataBaseDownloadPageState extends State<DataBaseDownloadPage> {
'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(() {
Expand Down
13 changes: 12 additions & 1 deletion lib/pages/download/download_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,18 @@ class _DownloadPageState extends ThemeSwitchableState<DownloadPage>
/// to
/// /var/mobile/Containers/Data/Application/<new-app-code>/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;
Expand Down
19 changes: 17 additions & 2 deletions lib/pages/main/info/lab/bookmark/bookmarks.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -170,8 +172,21 @@ class _BookmarkPageState extends State<LabBookmarkPage> {
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) {
Expand Down
Loading

0 comments on commit 07f0e83

Please sign in to comment.