• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Asset - Extension Unboxed - Non-sandbox filesystem

kagamma

Member


Unboxed is a free and open source extension written in Pascal for GMS2 that allows you to work with files and directories without having to deal with GM's limitations (or features).

Supports Windows, Linux (experiment), MacOS (experiment).

Please note that the Linux version hasn't been tested with GMS2 yet as I don't have a readily Linux system (same goes with MacOS). It was cross-compile from Windows to Linux/MacOS and then tested by calling it's functions via a Linux program running in WSL (Windows Subsystem for Linux). Any feedback on these platforms is appreciated :)

This extension currently supports:
  • Handling UTF-16 paths on Windows and UTF-8 paths on Linux/MacOS.
  • Copying, renaming, moving and deleting files.
  • Creating, renaming, moving and deleting directories.
  • Creating, reading and writing UTF-8 text files.
  • Searching for files and directories from a given path.
  • Get environment variables (there is a GMS equivalent for this function but it's Windows-only).
(Please see Unboxed-README.txt included in this asset for details)

Changelog:
v0.1.4:
  • Minor update for Unboxed-Code snippets.txt.
v0.1.2:
  • Fixed crash caused by file_text_eof_ue() when reading an invalid file.
  • Added Unboxed-Code snippets.txt contains example code for quick testing.
v0.1.1:
  • Fixed memory leak when closing file.
  • Fixed minor bugs in file_rename_ue() and directory_rename_ue() functions.
  • Added experiment support for Linux and MacOS.
v0.0.3:
  • Minor bugs fixed.
v0.0.1:
  • Public released.
 
Last edited:
S

Sam (Deleted User)

Guest
I would try to port the extension for you, but I don't know anything about Pascal.

Would it require me to modify anything? Would it work with the Lazarus IDE?
 

kagamma

Member
I would try to port the extension for you, but I don't know anything about Pascal.

Would it require me to modify anything? Would it work with the Lazarus IDE?
Actually no porting is required, as the code is already portable (only standard Free Pascal library is used, no platform-dependent APIs) and can be compiled on any platform supports by the compiler. In fact I already have both the Linux and MacOS version in my PC via cross-compiling from Windows but no actual testing with GMS2 yet as I don't have a readily Linux/MacOS system (I did test the Linux version by making calls from a simple program running on Windows Subsystem for Linux).

You can build it with Lazarus IDE. Or you can simply type "fpc ue.pas" via the command line.

Anyway new version is available (v0.1.1):
  • Fixed memory leak when closing file.
  • Minor bugs fixed in file_rename_ue() and directory_rename_ue() functions.
  • Added experiment support for Linux and MacOS. I haven't test them on GMS2 so any feedback on these platforms is appreciated.
 
S

Sam (Deleted User)

Guest
I'll let you know when I've tested it. Probably sometime tmr. I'm about to go to bed right now. I will test on both Mac and Linux if you want.
 

kagamma

Member
Thanks Samuel :)

I just upload a new version (v0.1.2) contains code snippet for quick testing and fixed a bug that cause the game to crash.
 
S

Sam (Deleted User)

Guest
Tested the sample script you gave on macOS High Sierra, but I have 2 critiques regarding that.

Here's the code you gave:
Code:
var path = "e:/temp/"; // Change this to your own testing environment.

// Create a new directory
directory_create_ue(path + "data");
// Verify "data" directory exists
if (directory_exists_ue(path + "data"))
    show_debug_message("Directory 'data' existed.");
else
    show_debug_message("[Failed] Directory 'data' not existed.");
   
// Rename "data" to "data_renamed"
directory_rename_ue(path + "data", path + "data_renamed");

// Verify "data_renamed" directory exists
if (directory_exists_ue(path + "data_renamed"))
    show_debug_message("Directory 'data_renamed' existed.");
else
    show_debug_message("[Failed] Directory 'data_renamed' not existed.");
   
// Create a new file at the same directory with the game
var f = file_text_open_write_ue(path + path + "data.txt");
// Write some texts to it
file_text_writeln_ue(f, "Hello, World!");
file_text_writeln_ue(f, "こんにちは!");
// Close the file
file_text_close_ue(f);

// Reopen file to write additional data at the end of the file
var f = file_text_open_append_ue(path + "data.txt");
file_text_writeln_ue(f, "Bye!");
file_text_close_ue(f);

// Open file, read all the content in the file and print to output window
var f = file_text_open_read_ue(path + "data.txt");
show_debug_message("--- data.txt content ---");
while (!file_text_eof_ue(f)) {
    show_debug_message(file_text_readln_ue(f));
}
file_text_close_ue(f);

// Copy "data.txt" to "ファイル.txt"
file_copy_ue(path + "data.txt", path + "ファイル.txt");

// List all files and directories
show_debug_message("--- Directory contents ---");
for (var f = file_find_first_ue(path + "*"); f != ""; f = file_find_next_ue()) {
    if (file_find_attributes_ue() & fa_directory)
        show_debug_message(f + " [DIR]");
    else
        show_debug_message(f + " (" + string(file_find_size_ue()) + " bytes)");
}
file_find_close_ue();
Here's what I think you should've done:
Code:
var path = "/Users/owner/Desktop/temp/"; // Change this to your own testing environment.

// Create a new directory
directory_create_ue(path + "data");
// Verify "data" directory exists
if (directory_exists_ue(path + "data"))
    show_message("Directory 'data' existed.");
else
    show_message("[Failed] Directory 'data' not existed.");
   
// Rename "data" to "data_renamed"
directory_rename_ue(path + "data", path + "data_renamed");

// Verify "data_renamed" directory exists
if (directory_exists_ue(path + "data_renamed"))
    show_message("Directory 'data_renamed' existed.");
else
    show_message("[Failed] Directory 'data_renamed' not existed.");
   
// Create a new file at the same directory with the game
var f = file_text_open_write_ue(path + "data.txt");
// Write some texts to it
file_text_writeln_ue(f, "Hello, World!");
file_text_writeln_ue(f, "こんにちは!");
// Close the file
file_text_close_ue(f);

// Reopen file to write additional data at the end of the file
var f = file_text_open_append_ue(path + "data.txt");
file_text_writeln_ue(f, "Bye!");
file_text_close_ue(f);

// Open file, read all the content in the file and print to output window
var f = file_text_open_read_ue(path + "data.txt");
show_message("--- data.txt content ---");
while (!file_text_eof_ue(f)) {
    show_message(file_text_readln_ue(f));
}
file_text_close_ue(f);

// Copy "data.txt" to "ファイル.txt"
file_copy_ue(path + "data.txt", path + "ファイル.txt");

// List all files and directories
show_message("--- Directory contents ---");
for (var f = file_find_first_ue(path + "*"); f != ""; f = file_find_next_ue()) {
    if (file_find_attributes_ue() & fa_directory)
        show_message(f + " [DIR]");
    else
        show_message(f + " (" + string(file_find_size_ue()) + " bytes)");
}
file_find_close_ue();
The only difference is, I replaced show_debug_message with show_message, and right before you started writing to text files in your code, you added the path variable twice, thus preventing half your demo from working. I removed the second time the path variable was added there, and everything in your demo script worked great! :D

I will test on Ubuntu next, and will let you know how that goes. :)
 

kagamma

Member
Great to hear it worked on MacOS! And thanks for pointing out my flaws so ninja update the asset. :oops:
Ubuntu should work as the way it's handled stuff is similar to MacOS but who knows the future is full of surprises :p
 
S

Sam (Deleted User)

Guest
I stand corrected, it would probably be better to use show_message_async now that show_message is deprecated. The only reason I said to replace show_debug_message is because for whatever reason, no debug message was showing for me, so I assumed the function was broken.

I am still going to test on Linux btw, but I am currently in the process of replacing my Linux OS's username, which in a dual boot, since creation of multiple accounts seems to be disabled, this means I have to reinstall Ubuntu entirely to change my username, which I won't be able to complete until tomorrow.

I'm sorry for taking so long! :(
 
Top