Update PR

Update PR
This commit is contained in:
abraunegg 2021-11-05 19:22:33 +11:00
parent 820e4b1e39
commit 5c04e35a3a
7 changed files with 72 additions and 18 deletions

View file

@ -134,7 +134,7 @@ final class Config
// display_sync_options = true | false
// - It may be desirable to see what options are being passed in to performSync() without enabling the full verbose debug logging
boolValues["display_sync_options"] = false;
// Determine the users home directory.
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts
// Check for HOME environment variable
@ -304,7 +304,7 @@ final class Config
boolValues["synchronize"] = false;
boolValues["force"] = false;
boolValues["list_business_shared_folders"] = false;
// Application Startup option validation
try {
string tmpStr;
@ -465,7 +465,11 @@ final class Config
&boolValues["list_business_shared_folders"],
"sync-shared-folders",
"Sync OneDrive Business Shared Folders",
&boolValues["sync_business_shared_folders"]
&boolValues["sync_business_shared_folders"],
"export-translations",
"Export existing default application messages in JSON format",
&tmpBol
);
if (opt.helpWanted) {
outputLongHelp(opt.options);

View file

@ -6,6 +6,7 @@ import std.stdio;
import std.algorithm.searching;
import core.stdc.stdlib;
import sqlite;
import translations;
static import log;
enum ItemType {
@ -42,16 +43,21 @@ final class ItemDatabase
string selectItemByIdStmt;
string selectItemByParentIdStmt;
string deleteItemByIdStmt;
string languageIdentifier;
this(const(char)[] filename)
{
languageIdentifier = getConfigLanguageIdentifier();
writeln("itemdb.d languageIdentifier: ", languageIdentifier);
db = Database(filename);
int dbVersion;
try {
dbVersion = db.getVersion();
} catch (SqliteException e) {
// An error was generated - what was the error?
// "\nAn internal database error occurred: " ~ e.msg ~ "\n"
log.error(provideLanguageTranslation(languageIdentifier,331) ~ e.msg ~ "\n");
exit(-1);
}

View file

@ -114,12 +114,16 @@ int main(string[] args)
string helpMessage = "Please use 'onedrive --help' for further assistance in regards to running this application";
try {
bool printVersion = false;
bool exportTranslations = false;
auto opt = getopt(
args,
std.getopt.config.passThrough,
std.getopt.config.bundling,
std.getopt.config.caseSensitive,
"confdir", "Set the directory used to store the configuration files", &confdirOption,
"export-translations", "Export existing default application messages in JSON format", &exportTranslations,
"verbose|v+", "Print more details, useful for debugging (repeat for extra debugging)", &log.verbose,
"version", "Print the version and exit", &printVersion
);
@ -132,6 +136,17 @@ int main(string[] args)
writeln("onedrive ", strip(import("version")));
return EXIT_SUCCESS;
}
// If we are dumping the existing default application messages in JSON format, do so, then exit
if (exportTranslations){
// EN only message
writeln("Exporting existing application messages in JSON format");
// Export application default messages
exportDefaultMessages();
// exit
return EXIT_SUCCESS;
}
} catch (GetOptException e) {
// option errors
log.error(e.msg);
@ -154,7 +169,7 @@ int main(string[] args)
// Error message already printed
return EXIT_FAILURE;
}
// --verbose --verbose used .. override any language setting to force EN-AU
if (cfg.getValueLong("verbose") >= 2) {
log.vdebug("Force application language to EN-AU due to debug operation");
@ -162,7 +177,9 @@ int main(string[] args)
}
// Use the configured application language
languageIdentifier = cfg.getValueString("language_identifier");
log.vlog("Application Language set to: ", languageIdentifier);
// Set the language identifier for wider use
setConfigLanguageIdentifier(languageIdentifier);
log.log("Application Language set to: ", languageIdentifier);
// set memory display
displayMemoryUsage = cfg.getValueBool("display_memory");

View file

@ -6,6 +6,7 @@ import core.stdc.stdlib;
import config;
import selective;
import util;
import translations;
static import log;
// relevant inotify events
@ -21,6 +22,7 @@ class MonitorException: ErrnoException
final class Monitor
{
// verbosity flag
bool verbose;
// inotify file descriptor
private int fd;
@ -34,6 +36,7 @@ final class Monitor
bool skip_symlinks;
// check for .nosync if enabled
bool check_nosync;
string languageIdentifier;
private SelectiveSync selectiveSync;
@ -53,6 +56,9 @@ final class Monitor
this.verbose = verbose;
this.skip_symlinks = skip_symlinks;
this.check_nosync = check_nosync;
this.languageIdentifier = getConfigLanguageIdentifier();
writeln("monitor.d languageIdentifier: ", languageIdentifier);
assert(onDirCreated && onFileChanged && onDelete && onMove);
fd = inotify_init();

View file

@ -54,22 +54,21 @@ struct Database
void dump_open_statements()
{
log.log("Dumpint open statements: \n");
writeln("Dumping open SQL statements: \n");
auto p = sqlite3_next_stmt(pDb, null);
while (p != null) {
log.log (" - " ~ ifromStringz(sqlite3_sql(p)) ~ "\n");
writeln(" - " ~ ifromStringz(sqlite3_sql(p)) ~ "\n");
p = sqlite3_next_stmt(pDb, p);
}
}
void open(const(char)[] filename)
{
// https://www.sqlite.org/c3ref/open.html
int rc = sqlite3_open(toStringz(filename), &pDb);
if (rc == SQLITE_CANTOPEN) {
// Database cannot be opened
log.error("\nThe database cannot be opened. Please check the permissions of ~/.config/onedrive/items.sqlite3\n");
log.error("\nThe database cannot be opened. Please check the permissions of " ~ filename ~ "\n");
close();
exit(-1);
}

View file

@ -296,7 +296,9 @@ final class SyncEngine
JSONValue oneDriveRootDetails;
// Update language identifier as used with this class
languageIdentifier = cfg.getValueString("language_identifier");
languageIdentifier = getConfigLanguageIdentifier();
writeln("sync.d languageIdentifier: ", languageIdentifier);
if (initDone) {
return;

View file

@ -10,14 +10,33 @@ ulong defaultMessageCount = 0;
string[] languageResponsesDefault;
string[] languageResponsesTranslations;
string defaultBadLookupResponse = "ERROR: BAD LOOKUP INDEX FOR LANGUAGE TRANSLATION";
JSONValue languageListDefault;
string configLanguageIdentifier;
// Initialise default message lookup using EN-AU
void initialize() {
// Initialise default messages
initialise_EN_AU();
initialise_defaults();
defaultMessageCount = count(languageResponsesDefault);
}
void exportDefaultMessages() {
// Initialise default messages
initialise_defaults();
// Print JSON Array
writeln(languageListDefault);
}
void setConfigLanguageIdentifier(string languageIdentifier) {
// set the local variable
configLanguageIdentifier = languageIdentifier;
}
string getConfigLanguageIdentifier() {
// return the current set language identifier as per config or set by user
return configLanguageIdentifier;
}
// Load user configured translation files from a file
void initializeUserConfiguredLanguageTranslations(string languageIdentifier) {
// Path to translation files
@ -148,10 +167,12 @@ string getResponseFromIndex(int requiredResponseIndex) {
}
// Load EN-AU application messages
void initialise_EN_AU(){
void initialise_defaults(){
// The below JSON array contains all the default application messages
JSONValue languageList = [ "language": "EN-AU"];
languageList.object["list"] = JSONValue([
// Default Language Type
languageListDefault = [ "language": "EN-AU"];
// Application Messages
languageListDefault.object["list"] = JSONValue([
JSONValue([ "1": "No user or system config file found, using application defaults" ]),
JSONValue([ "2": "System configuration file successfully loaded" ]),
JSONValue([ "3": "System configuration file has errors - please check your configuration" ]),
@ -484,7 +505,6 @@ void initialise_EN_AU(){
JSONValue([ "330": "Removed this directory from being monitored for local changes: " ]),
JSONValue([ "331": "\nAn internal database error occurred: " ]),
JSONValue([ "332": "The item database is incompatible, re-creating database table structures" ]),
JSONValue([ "330": "Removed this directory from being monitored for local changes: " ]),
@ -492,7 +512,7 @@ void initialise_EN_AU(){
// Load the message into the array
ulong thisMessageID = 0;
foreach (translationItem; languageList["list"].array) {
foreach (translationItem; languageListDefault["list"].array) {
thisMessageID++;
string responseString = translationItem[to!string(thisMessageID)].str;
languageResponsesDefault ~= responseString;