How to access a OS X user's file system with React VR? - json

I'm developing an Electron app that is running an instance React VR. The app enables a user to add and save content to a react-vr project by reading and writing the state from/to a JSON file. During development, this JSON file has been stored in the root directory. However, if a user is to download and use the app on their computer, the JSON file needs to be moved outside the app package contents folder.
I have tried using app.getpath('userdata') which returns /Users/'username'/Library/Application Support/'app_name', and I can move the JSON state file there successfully upon running the app. However, I don't know how to have react-vr access this file, especially since there is no access to the computer's file system. However, all I really need is the user's system username to include in the 'userdata' file path.
What's the best way to go about retrieving the username from within react-vr? Would there be a better way to persist user data instead of a using a JSON file to keep track of the state? Would it be worth considering using AsyncStorage in conjunction with a database? Many thanks.

Related

Storing and loading data from react-native calendar to a JSON file

I'm currently thinking of a concept for a react-native app where people add events over a period of time like a diary/log. These events need to be exported and for security and privacy reasons I don't want to use a database. I've read you can use JSON files as a storage method, too.
How can I store data from the app to a JSON file and load the data from the JSON file back in the app? Don't need any code, helpful articles or webpages are appreciated
Assuming that you already have all the app data into a json, its rather simple.
Decide where to store the appdata.json, lets call it APP_DATA_PATH
Find a library to read/write files (I've only used expo-file-system)
On app boot, check if APP_DATA_PATH exists, if it does read the file and load into app, if not assume its a new user
Whenever app data changes, write the changes to APP_DATA_PATH

synchronizing json files on device with a database

I want to synchronize data from a nosql database, have it emit json, and when there is a change and the app is online, have the app pull the changes and update them.
My react-native app uses a few language-specific json files loading them dynamically into javascript objects and then using them as my "database". One file for rendering content, one for the app texts, and one for the styles.
When the user changes the language a different directory is used with the same set of json filenames. This is done via the index.js in that directory and loaded into redux.
Must I change the way my app works, and use a NoSQL/real database directly in the app? So that I can use a solution like this one: synchronizing pouchDB with json data
(that solution is for working if I understand correctly in the exact opposite direction. The app is working with a database and synchronizing with json received from the web)
Or can I update the data in an external (preferably) NoSQL (pouchDB or couchDB) or relational database, and somehow "synchronize" it with the json files, when the app is connected to the web and have it update?
Is there a known method or framework to accomplish this with react-native?

AS3 write string to an existing text file

I'm running my program on AIR. I want my game to save the high score to a text file so it can be stored when the program is closed. I've tried using filestreams, however I've found that the application directory is read only. Is there a better way to do this?
The AIR application storage directory is designed for saving these sorts of preferences and user settings:
For every AIR application, there is a unique associated path that
defines the application storage directory. This directory is unique to
each application and user. You can use this directory to store
user-specific, application-specific data (such as user data or
preferences files).
Access it through the File class:
var file:File = File.applicationStorageDirectory;
file = file.resolvePath("prefs.xml");
See also: Reading from and writing to an XML preferences file
The only caveat I have found with using this directory is that it does not get removed when the AIR app is uninstalled using the .air installer/uninstaller.

Chrome app create and write to file

I am attempting to use chrome.apps for a program that needs to write multiple separate log files of data. The user then needs to be able to access these these log files outside of the app in their file system for post processing.
This will need to be done many times so minimum to no user interaction would be desired for file generation. While this is simple in any native program code, I've been finding this very difficult to do with chrome apps.
E.g. can I use chrome apps to create "log_file.txt" & "log_file2.txt" without user interaction?
Is there any way I can have the user just specify a directory then from my app, I would be able to create multiple files within that directory without user interaction?
I've tried to do this in code but I need "entry" handles for the chrome.filesystem. The "getEntry" method requires an "entry" so it seems impossible to create new "entry"s such that I can write to new files.
Any ideas would be appreciated!
Is there any way I can have the user just specify a directory then from my app, I would be able to create multiple files within that directory without user interaction?
Yes. You need to request a directory with
chrome.fileSystem.chooseEntry({type: "openDirectory"}, /*...*/);
As long as you have the permissions
{"fileSystem": ["write", "retainEntries", "directory"]}
you will be able to create files in that directory, and "retain" (save) the directory entry for later reuse without asking the user again. Creating the files once you have a DirectoryEntry should be similar to this.
But that minimum of interaction (asking for the folder initially) is required.

Is there a way to create a directly accessible URL to a file stored as varbinary(max) in a mySQL database?

I have a number of different types of files stored in a MySQL database (varbinaryMAX). I am in the process of building a document management system and my final phase is to install some sort of document viewer so that these files can be prievewed.
I have veered away from Google Docs due to the security of the documents. I have [preliminarily] settled with Viewer.JS as my chosen method of preview as it supports a wide variety of filetypes, and is free. It does however require a directly accessible URL for the file, which I of course dont have as the file is sitting in a coloumn in the DB.
How would I go about generating a URL that can be used to access a/the file in the DB?
Application is ASP.net