Page 1 of 1

Load File as Binary into a string

Posted: Tue Aug 14, 2012 9:55 am
by fingus
How to do that?
I need hex Values for each Position inside the string.

openfile and filetostring don´t seem to do it right.

Re: Load File as Binary into a string

Posted: Tue Aug 14, 2012 12:57 pm
by Bugala
Might not help you since it requires those files first be created with Hollywood.

But what i have been doing is to save tables as binary. Dont remember rightaway, but i think the command was maybe simpy SaveTable and LoadTable.

example code (commands might not be right):

Code: Select all

mytable = {x=10, y=200}
SaveTable(mytable, "myfilename")

mysecondtable = LoadTable("myfilename")
debugprint(mysecondtable.x)
debugprint(mysecondtable.y)
will result in:

10
200

Re: Load File as Binary into a string

Posted: Fri Aug 17, 2012 6:28 pm
by airsoftsoftwair
To get the ASCII value of a string character, just use

Code: Select all

c = Asc(MidStr(s$, xxx, 1))
where "xxx" is the offset of the character starting from 0. If you want the value as hex, use

Code: Select all

c = HexStr(Asc(MidStr(s$, xxx, 1)))

Re: Load File as Binary into a string

Posted: Sun Aug 19, 2012 12:01 am
by fingus
Thanks for your valuable hint Andreas!

Here's the result how to know if Compositing for Windows on Workbench is enabled or not:

Code: Select all

OpenFile(1,"SYS:Prefs/Env-Archive/Sys/gui.prefs")
s$ = ReadLine(1)
CloseFile(1)
c = HexStr(Asc(MidStr(s$, 58, 1)))
if c = "$3" then o = "Compositing is on"
if c = "$2" then o = "Compositing is off"
DebugPrint(o)                      
Here is how i get the knownledge what byte is responsible for it:
Image

Re: Load File as Binary into a string

Posted: Sun Aug 19, 2012 10:54 pm
by airsoftsoftwair
Keep in mind that the offset can change with every new version of OS4 so directly peeking at a hard-coded offset is not a clean way that ensures future compatibility :-)

Btw, you don't have to use HexStr() for that at all. You can also just use:

Code: Select all

c = Asc(MidStr(s$, 58, 1))
if c = $3 then o = "Compositing is on"
if c = $2 then o = "Compositing is off"

Re: Load File as Binary into a string

Posted: Mon Aug 20, 2012 9:32 am
by fingus
Andreas wrote:Keep in mind that the offset can change with every new version of OS4 so directly peeking at a hard-coded offset is not a clean way that ensures future compatibility :-)
I know, for this case i will have a "compositing off" fallback, if this byte don´t return a valid value. Another way is to look which version of Workbench/GUIPrefs is installed/running.
Btw, you don't have to use HexStr() for that at all. You can also just use:

Code: Select all

c = Asc(MidStr(s$, 58, 1))
if c = $3 then o = "Compositing is on"
if c = $2 then o = "Compositing is off"
Very useful!

Re: Load File as Binary into a string

Posted: Fri Dec 16, 2016 2:52 pm
by jPV
Is there any way in Hollywood itself to check if compositing is on nowadays? For MorphOS and OS4 at least... I have no idea about AROS, but if it has a similar situation, that too :)

I thought I've seen such thing, but now it seems that I can't find any info about it. So if it's not there still, could we get such a function (ASAP)? :) I'm making a program with alpha transparent windows, which is progressing nicely, but when I now started to think about making a fallback solution for traditional modes, I can't seem to find any clean solution to find it out. Having user to select something manually will be out of question...

Re: Load File as Binary into a string

Posted: Sat Dec 17, 2016 1:44 pm
by airsoftsoftwair
No, it's currently not possible. I could add this to Hollywood but of course I prefer to keep platform-specific APIs at a minimum level. Isn't it possible to find out whether compositing is enabled using some other means? (maybe env variables, Rexx script, examining system prefs or some 3rd party tool?)

Re: Load File as Binary into a string

Posted: Sat Dec 17, 2016 7:34 pm
by jPV
In MorphOS you can read it in plain text from ENV:MUI/screens.txt, but reading this thread it seems to be more uncertain with OS4. I don't have proper setups for OS4 and AROS to find it out... anyone else done any research? I'd rather avoid any 3rd party tools and offer my program without dependencies.