I am having trouble loading a JSON file from a folder named saveFiles, which is located in the same directory as the nw.exe and package.json files (manifest file). Currently, the program saves the JSON file to the C:\Users\userName\AppData\Local\appName\User Data\Default folder. I have been trying to change the destination folder by adjusting the "chromium-args": "--data-path=''" value in the manifest package.json file. However, I am unsure of what value to use for it to work properly. Here is how my package.json looks like at the moment:
{
"main": "index.html",
"name": "appName",
"chromium-args": "--data-path='./saveFiles/'",
"window":
{
"toolbar": true,
"width": 1600,
"height": 900,
"min_width": 1000,
"min_height": 500,
"fullscreen": true,
"title":"App Name"
}
}
Despite trying different variations such as --data-path='./saveFiles/', --data-path='/saveFiles/', --data-path='saveFiles/', I have not been successful in changing the save location. Could my format be incorrect? Is there an alternative way to modify the save location/directory?
Additional Information:
When saving the JSON file, the following code is used:
var fs = require('fs');
var path = require('path');
function saveSettings (settings, callback) {
var file = 'testSave.json';
var filePath = path.join(nw.App.dataPath, file);
fs.writeFile(filePath, settings, function (err) {
if (err) {
console.info("There was an error attempting to save your data.");
console.warn(err.message);
return;
} else if (callback) {
callback();
}
});
}
var mySettings = {
color:'red',
secondaryColor:'blue'
}
mySettings = JSON.stringify(mySettings);
saveSettings(mySettings, function () {
console.log('Settings saved');
});
Although this code successfully saves the file to the C:\Users\userName\AppData\Local\appName\User Data\Default folder, the goal is to save it into the saveFiles folder (located alongside the manifest file and nw.exe).
The load function to read the JSON file appears as follows:
function testLoadFunc(){
path = require('path');
var xmlhttp = new XMLHttpRequest();
var url = "saveFiles/testSave.json";
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var loadedSettings = JSON.parse(this.responseText);
console.log('color: ' + loadedSettings.color);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
testLoadFunc(); //Loads json file
This method loads the file correctly, but currently requires manually placing testSave.json into the saveFiles folder. The aim is to automate the process and save testSave.json directly into the saveFiles folder.
An alternate approach could involve learning how to load the file from the current save location (C:\Users\userName\AppData\Local\appName\User Data\Default), although that remains uncertain to me as well. Ideally, I would prefer to simply change the save location to the saveFiles folder.
Any assistance provided would be greatly appreciated. Thank you.