I'm currently doing a project in Danmakufu that involves writing to and then reading from file. However, opening the file always fails and I'd like to know why.
First, the code that creates the file:
let outputfile = ObjFile_Create(OBJ_FILE_TEXT);
let outputfilepath = OUTPUT_DIRECTORY ~ "apmfps-" ~ starttime ~ ".csv";
ObjFile_OpenNW(outputfile, outputfilepath);
...
// Flush to file
ObjFileT_AddLine(outputfile, csvlog);
ObjFile_Store(outputfile);
WriteLog("APM_StartFPS: Wrote CSV to " ~ outputfilepath);
Obj_Delete(outputfile);
// yield once before marking as complete
yield;
finished_fps = true;
WriteLog("APM_StartFPSDEBUG: Finished");
In another function, I wait for this task to finish before proceeding:
while (!finished_fps) {yield;} //Wait for file to be written before reading
ObjFileT_AddLine(outputfile, APM_ChartGenFPS);
This is a separate File Object that I am writing to.
APM_ChartGenFPS is implemented as follows:
function APM_ChartGenFPS {
WriteLog("APM_ChartGenFPS: Starting.");
let svg = SVGChartGen;
let paths = [];
let maxfps = 0;
let filepath = OUTPUT_DIRECTORY ~ "apmfps-" ~ starttime ~ ".csv"; // Current run
//filepath = OUTPUT_DIRECTORY ~ "apmfps-20180627142126.csv"; //debug
let datapoints = CSVtoArray(filepath);
maxfps = maxarr(datapoints);
WriteLog("APM_ChartGenFPS Debug: Maximum FPS is " ~ ToString(maxfps));
...
}
Note that filepath is EXACTLY the same as the output file path from before.
In CSVtoArray, the following is done:
function CSVtoArray(filepath) {
WriteLog("CSVtoArray: Running on " ~ filepath);
let handle = ObjFile_Create(OBJ_FILE_TEXT);
let status = ObjFile_Open(handle, filepath);
while (!status) {
//WriteLog("CSVtoArray: Reading file " ~ filepath ~ " failed.");
status = ObjFile_Open(handle, filepath);
yield;
}
WriteLog("CSVtoArray: Successfully read file " ~ filepath ~ ".");
let toreturn = [];
ascent(i in 0..ObjFileT_GetLineCount(handle)) { // For every line
let line = ObjFileT_GetLineText(handle, i + 1); // Recall that lines are 1-indexed
let split = SplitString(line, ",");
ascent(j in 0..length(split)) {
toreturn = toreturn ~ TrimString(split[j]);
}
}
Obj_Delete(handle);
return toreturn;
}
The code, when run, never gets past the infinite while loop - status is never set to true, the Success message never prints. Even after the file has shown up in my computer and I can open it, ObjFile_Open continues to fail.
APM_StartFPS: Wrote CSV to Z:/Users/andrewfan/Desktop/THDNH ph3pre6a/script/ Sparen DNH APM/test/./dnhapm-output/apmfps-20180627144737.csv
2018/06/27 14:47:40.765 APM_StartFPSDEBUG: Finished
2018/06/27 14:47:40.775 APM_ChartGenFPS: Starting.
2018/06/27 14:47:40.787 CSVtoArray: Running on Z:/Users/andrewfan/Desktop/THDNH ph3pre6a/script/ Sparen DNH APM/test/./dnhapm-output/apmfps-20180627144737.csv
2018/06/27 14:47:42.648 force terminate
As you can see in the above, it's *writing* properly, and CSVtoArray is running on the same file path as the file that was written. However, ObjFile_Open fails continuously in the while loop. I can confirm that the file exists locally. And if I hardcode the filepath, ObjFile_Open actually works (see the debug statement in APM_ChartGenFPS).
So my question(s) are:
- Is ObjFile_Store() blocking, as in, if you call it, will the next line of code not execute until the file has been written? (Confirmed blocking)
- Is ObjFile_Open() blocking? (Confirmed blocking)
- Does ObjFile_Open() only know about files that existed when the script was first run, or does it have access to the current files as of function call? If the former is true, is there a way to notify Danmakufu about the current files?
- Are there any standard ASCIIcharacters that cannot be placed in filenames in Danmakufu (spaces, hyphens, /, \)?
- Am I crazy? Is this Danmakufu being weird? Is it a stupid oversight?
Thanks.