Opening write stream problem in BlitzmaxNG?

Started by Baggey, September 07, 2024, 18:59:18

Previous topic - Next topic

Baggey

Hi, Could someone test this for me. I cant seem to write to the C:/ drive ??? 
if i leave C:/ out it writes to the folder where .bmx is.

I have no idea why this is not working? Ive done this before? I dont seem to be seeing the wood through the trees? :-[
' writestream.bmx

' opens a write stream to the file mygame.ini and
' outputs a simple text file using WriteLine

SuperStrict

Local filename:String="C:/mygame.txt"

Local out:TStream = WriteStream(filename)

If Not out RuntimeError "Failed to open a WriteStream to file "+filename

WriteLine out,"[display]"
WriteLine out,"width=800"
WriteLine out,"height=600"
WriteLine out,"depth=32"
WriteLine out,""
WriteLine out,"[highscores]"
WriteLine out,"AXE=1000"
WriteLine out,"HAL=950"
WriteLine out,"MAK=920"

CloseStream out

Print "File "+filename+" created, bytes="+FileSize(filename)

if it works for you then do you think i have some Blitzmax build settings wrong or windows file properties wrong? I am the administrator of course!?

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on Acer 24" . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Amiga mini, ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

SToS

I presume this is on a Windows system as you use C: for the drive, therefore (correct me if I am wrong) doesn't Windows still use backslash and not forward slash as the path separator?

dawlane

#2
Quote from: SToS on September 07, 2024, 20:21:27I presume this is on a Windows system as you use C: for the drive, therefore (correct me if I am wrong) doesn't Windows still use backslash and not forward slash as the path separator?

On Windows. The file path separator can be either back or forward facing slashes.
Quote from: Baggey on September 07, 2024, 18:59:18I have no idea why this is not working?
Sounds like a permissions problem. Drive C: is a restricted drive. Create a folder with the correct permissions and write the file in to it.
Those tutorials were written back in the time when it was still possible to write to drive C:\ without the UAC getting in the way.

Dabz

This works for me...

SuperStrict
Local BaggeysFolder:String = "C:\BaggeysFolder"
If FileType(BaggeysFolder) = 0
Print "Attempting to create folder"
Local result:Int = CreateDir(BaggeysFolder)
If Not result Then RuntimeError("Proper tits up")
Print "Yummmyyyyyyy"
EndIf

Local filePath:String=BaggeysFolder+"\mygame.txt"

Local out:TStream = WriteStream(filePath)
If Not out RuntimeError "If Not out... Sounds like cricket! Rain stops play! :P"

WriteLine out,"[display]"
WriteLine out,"width=800"
WriteLine out,"height=600"
WriteLine out,"depth=32"
WriteLine out,""
WriteLine out,"[highscores]"
WriteLine out,"AXE=1000"
WriteLine out,"HAL=950"
WriteLine out,"MAK=920"

CloseStream out

Print "File "+filePath+" created, bytes="+FileSize(filePath)

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Baggey


QuoteSounds like a permissions problem. Drive C: is a restricted drive. Create a folder with the correct permissions and write the file in to it.
Those tutorials were written back in the time when it was still possible to write to drive C:\ without the UAC getting in the way.

What is the UAC :-[ My thoughts are a permission problem ive recently changed the HardDisk?

Thanks
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on Acer 24" . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Amiga mini, ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

Quote from: Dabz on September 07, 2024, 23:33:12This works for me...

SuperStrict
Local BaggeysFolder:String = "C:\BaggeysFolder"
If FileType(BaggeysFolder) = 0
Print "Attempting to create folder"
Local result:Int = CreateDir(BaggeysFolder)
If Not result Then RuntimeError("Proper tits up")
Print "Yummmyyyyyyy"
EndIf

Local filePath:String=BaggeysFolder+"\mygame.txt"

Local out:TStream = WriteStream(filePath)
If Not out RuntimeError "If Not out... Sounds like cricket! Rain stops play! :P"

WriteLine out,"[display]"
WriteLine out,"width=800"
WriteLine out,"height=600"
WriteLine out,"depth=32"
WriteLine out,""
WriteLine out,"[highscores]"
WriteLine out,"AXE=1000"
WriteLine out,"HAL=950"
WriteLine out,"MAK=920"

CloseStream out

Print "File "+filePath+" created, bytes="+FileSize(filePath)

Dabz
Thanks Dabz this works for me to!? But why with the creation of the folder? ::)

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on Acer 24" . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Amiga mini, ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

Quote from: SToS on September 07, 2024, 20:21:27I presume this is on a Windows system as you use C: for the drive, therefore (correct me if I am wrong) doesn't Windows still use backslash and not forward slash as the path separator?

Yes it's a windows10 x 64bit System

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on Acer 24" . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Amiga mini, ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

Hey @Dabz is that a detection of Sid the Sexist in there?
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on Acer 24" . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Amiga mini, ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

dawlane

#8
Quote from: Baggey on September 08, 2024, 09:27:01What is the UAC :-[ My thoughts are a permission problem ive recently changed the HardDisk?
UAC = User Access Control. The dialogue box that pops up when you install a program.

Changing the hard disk shouldn't be a problem. If you've cloned the drive, then all permissions will be copied and the size of the new drive shouldn't affect them.
The only time you need to mess with permissions is when you've got a second hard drive installed and you've reinstalled Windows on the first drive. You'll find that trying to access things on the second drive will request permissions.

Quote from: Baggey on September 08, 2024, 09:28:13Thanks Dabz this works for me to!? But why with the creation of the folder?
Windows doesn't allow any file to be written to the main boot drive for security reasons.  Even if you have an administrator account, you cannot write or modify a file in there. But you can write a folder. Helps prevent malicious code being injected into the boot sequence.

Baggey

QuoteThe only time you need to mess with permissions is when you've got a second hard drive installed and you've reinstalled Windows on the first drive. You'll find that trying to access things on the second drive will request permissions.
That's happened. But it's not the secondary drive im having problems with?

QuoteWindows doesn't allow any file to be written to the main boot drive for security reasons.  Even if you have an administrator account, you cannot write or modify a file in there. But you can write a folder. Helps prevent malicious code being injected into the boot sequence.
It used to work that way :-X

So on my old Hard drive with Windows10 on it, must of had full access some how? ::) I have copied my backups of .bmx onto the new SSD and the latest copy of BlitzmaxNG as well.

Kind Regards Baggey



Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on Acer 24" . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Amiga mini, ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Dabz

QuoteSid the Sexist

Being born and bred in the North-East, and grew up with Viz, aye.... T[beeeeeep]ts oooooooooootttttt! ;)

Dabz

Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Baggey

#11
I have fond memories of newcastle when i was a kid.

My grandad taught me "Hadawweer 'n' tidle with yuh"
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on Acer 24" . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Amiga mini, ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

wadmixfm

Hi baggey , i had problems writing my songs to the C:\ drive but i found out that i could install my program to the C:\Users\Public folder and there has been no issues for me with windows 11

lee

Yes its really me :)

Dabz

Ideally, you should be writing these things to somewhere in the appdata folder... Only problem is, they've mucked about with how to actually get these things so many times, I now just use this (On Windows):-

char* GetEnvAppDataPath()
{
return(getenv("APPDATA"));
}

Which you plonk in a C file, then import said C file in your Blitzmax source, e.g.

Import "c_code.c"

Then to use it in Blitzmax:-

Extern
Function GetEnvAppDataPath:Byte Ptr()
End Extern

Local appDataPath:String = String.FromCString(GetEnvAppDataPath())
Print "*"+appDataPath+"*"
End

Bare in mind, this isnt the "safest" way, not in a security sense, but valid path sense, I've had no bother with it at all though, but, consider checks on the returned path none the less, I also have another one which returns the users temp folder, just replace the "APPDATA" string with "TEMP", and in goes your eye out. <--- And before anyone asks, why don't I just pass a string with the name of the special folder and have something like SystemProperty("BLAH") like other Blitz languages... All I can say is, meh! :P

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Derron

SuperStrict

Framework BRL.Volumes
Import BRL.Standardio

Print GetUserAppDir()
Print GetUserDesktopDir()
Print GetUserHomeDir()
Print GetUserDocumentsDir()

More to read there: https://blitzmax.org/docs/en/api/brl/brl.volumes/



bye
Ron