File_Manipulation - hpgDesigns/hpgdesigns-dev.io GitHub Wiki

The nice thing about emulating such a file manipulation library as Game Maker's is that the method of identifying a file is an integer, like everything else, which remains compliant with a 2-component variant data type. Though many may prefer to keep track of the FILE pointer themselves, this is a convenient method for those who don't wish to concern themselves with such.

Classes

Achieving a unified storage class between text, binary, and ini file manipulation is relatively simple due to the range of functions offered by the original Game Maker library. The binary file functions offered a method to clear the file and start anew; this requires reopening the file by its original name, which would need to be stored in that case. Text files likewise require a string to store the last line read. Neither category needs use of both.

That being the case, text and binary files are stored in a single structure containing a FILE* member and a string member.

Text File Functions

  • Opens a text file for reading.

  • Opens a text file for writing.

  • Opens a text file for writing, but begins at the end of the file if it exists.

Differences

For efficiency concerns, a slight modification was made to text file behavior. While Game Maker does its reading in file_text_read_string/real, and just sets variables in file_text_readln and file_text_open, ENIGMA reads the first line in the file as soon as a call to open is made. This saves a check in calls to file_text_read_ string()/_real() down the road, but causes file_text_open_read() itself to take slightly longer. Typical use of these functions will introduce no visible difference, save minute speedup.

Binary File Functions

opens the file fname as a binary file with the given mode, which is an integer from the table below.

Name Value Description
Read 0 Opens the file for reading.
Write 1 Opens the file for writing.
Both 2 Opens the file with read and write permissions.

C/C++ File Functions

Again, since EDL is extended upon C++, you still have access to the lower level file functions if you desire to access those. These include the C stdio functions, fopen, fread, fwrite, and fclose, in which case you would need to keep the FILE pointer, rather than just the variant integer.