Printing to SD card (x3g files, Replicator) has a problem, in that if the card is full it creates a zero bytes file, and if the card is not full but does not have enough space to write the complete file it writes the partial file and fills the card. Most critically, in both failure cases, the operation looks to the user like it completes successfully, resulting in failed prints. What should happen is that if the file cannot be written to the SD card, there is an error back to the user, and nothing should be written to the SD card.
I would suggest that the gcode and the X3G file should be written to a temporary location, than the file size checked against you the available Space on the ST card, and if there's sufficient space then the files should be moved onto the SD card. This would be more resilient, and is also better for the SD card because a single large write is much better for its longevity then numerous small writes as the files are generated.