Check if drive is HDD possible?
BlitzMax Forums/BlitzMax Beginners Area/Check if drive is HDD possible?
| ||
Hello! Is there a way to check if the drive a program is started from is a HDD/USB-STICK or non re-writeable CD/DVD-ROM? Thanks. |
| ||
A pretty crude sort of half-effective method might be to read the file attributes of either the executable or one of its resource files and see if the read-only attribute is set. Unless it has been set that way on the medium by the user or the installer, you could assume that a read-only flag would indicate a CD or non-writable media. |
| ||
Or, you could try and open a file for writing only, and see if a file handle is returned. If yes, it's writeable (so HDD or other), if not it's a CD drive. If it turns out to be a HDD, close the file and then delete it again. |
| ||
Jazz, you mean this way: out=WriteStream("write.tmp") if not out then hdd_found=false closefile(out) else hdd_found=True closefile(out) deletefile(out) endif That's nice and simple! :) |
| ||
Yeah, just like that. I'd try it on a CD ROM or a write-protected floppy to make sure it actually works. You probably won't need the CloseFile() if the stream wasn't opened though. |
| ||
If on a non-readonly media, how can you be sure the file isn't replaced with a new and empty one ready for writing? (until it's too late, that is) |
| ||
Because usually you'd try and open a file for writing in your program's directory, so you'd know that whatever filename you are using for this purpose wouldn't be a file that is actually used by the game. Or, you could check to see if a file already exists with that name and if it does, use another one. It would be a simple matter of going through 'test1.dat', 'test2.dat', etc. |