Load File as Binary into a string

Discuss any general programming issues here
Post Reply
User avatar
fingus
Posts: 144
Joined: Fri Sep 16, 2011 9:53 am

Load File as Binary into a string

Post by fingus » Tue Aug 14, 2012 9:55 am

How to do that?
I need hex Values for each Position inside the string.

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

Bugala
Posts: 734
Joined: Sun Feb 14, 2010 7:11 pm

Re: Load File as Binary into a string

Post by Bugala » Tue Aug 14, 2012 12:57 pm

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

User avatar
airsoftsoftwair
Posts: 2962
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Load File as Binary into a string

Post by airsoftsoftwair » Fri Aug 17, 2012 6:28 pm

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)))

User avatar
fingus
Posts: 144
Joined: Fri Sep 16, 2011 9:53 am

Re: Load File as Binary into a string

Post by fingus » Sun Aug 19, 2012 12:01 am

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

User avatar
airsoftsoftwair
Posts: 2962
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Load File as Binary into a string

Post by airsoftsoftwair » Sun Aug 19, 2012 10:54 pm

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"

User avatar
fingus
Posts: 144
Joined: Fri Sep 16, 2011 9:53 am

Re: Load File as Binary into a string

Post by fingus » Mon Aug 20, 2012 9:32 am

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!

User avatar
jPV
Posts: 237
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Load File as Binary into a string

Post by jPV » Fri Dec 16, 2016 2:52 pm

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...

User avatar
airsoftsoftwair
Posts: 2962
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Load File as Binary into a string

Post by airsoftsoftwair » Sat Dec 17, 2016 1:44 pm

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?)

User avatar
jPV
Posts: 237
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Load File as Binary into a string

Post by jPV » Sat Dec 17, 2016 7:34 pm

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.

Post Reply