adventuregamestudio / ags-manual

AGS documentation.
https://adventuregamestudio.github.io/ags-manual/
MIT License
28 stars 9 forks source link

Document new File functions (Copy, Rename, GetFileTime, Read/WriteRawFloat, Read/WriteBytes) #262

Open ericoporto opened 1 day ago

ericoporto commented 1 day ago

https://github.com/adventuregamestudio/ags-manual/wiki/File

  /// Creates a copy of an existing file; if there's already a file with the new name then it will be overwritten
  import static bool Copy(const string old_filename, const string new_filename);   // $AUTOCOMPLETESTATICONLY$
  /// Retrieves specified file's last write time; returns null if file does not exist
  import static DateTime* GetFileTime(const string filename); // $AUTOCOMPLETESTATICONLY$
  /// Renames an existing file; if there's already a file with the new name then it will be overwritten
  import static bool Rename(const string old_filename, const string new_filename);   // $AUTOCOMPLETESTATICONLY$
  /// Reads the next raw 32-bit float from the file.
  import float  ReadRawFloat();
  /// Writes a raw 32-bit float to the file.
  import void   WriteRawFloat(float value);
  /// Reads up to "count" number of bytes and stores them in a provided dynamic array, starting with certain index. Returns actual number of read bytes.
  import int    ReadBytes(char bytes[], int index, int count);
  /// Writes up to "count" number of bytes from the provided dynamic array, starting with certain index. Returns actual number of written bytes.
  import int    WriteBytes(char bytes[], int index, int count);

Some of the new File API were added in PR https://github.com/adventuregamestudio/ags/pull/2541

Additional documentation in the source code https://github.com/adventuregamestudio/ags/blob/e7fc02178d50e808134a651f4a9e07d3d7cc65e0/Engine/ac/file.cpp#L87

A few notes

ivan-mogilko commented 1 day ago

File.Copy returns false if it fails and true if it executes correctly. File.Rename creates any dir necessary and also returns false if it fails or true if it succeeds.

IIRC File.Copy also should create directories.

But the engine only creates subdirs within the standard locations ($SAVEGAMEDIR$ and others), it is forbidden from creating directories outside of those.