DropBox integration with GLBasic - experimental work in progress

Previous topic - Next topic

spacefractal

If I run and write #TEMP#, then its would open Explodere with Temp folder directory. Howover I trying to do that with #DROPBOX#, because I think its would been cool if I could get DROPBOX to work on a least iOS, Android, Windows and Mac. Howover Android require Java and then its impossible to due as long you cant call java from inline.

on Windows its would been so simple as #DROPBOX# that get the user folder, but its not working with either SETCURRENTDIR() as well DOESDIREXIST(). If its worked with SETCURRENTDIR$(), then there would been compare with a simple string test.

this is not a glbasic bug, but would been nice if that was possible, eventuelly using inline?

PS. Im trying to use DROPBOX for the game could SYNC with thier devices (regaardless on system, except by now WebOS and Android). If I got success, then I put its in code snippet. But there is no final date on that yet, nor even its would relaese with Greedy Mouse v1.0.

[attachment deleted by admin]
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

okee

#1
#TEMP# is probably just GLBasic accessing the user variable TEMP in the Windows Environment Variable.
If you type %temp% in the Start\Run text box it'll open your temp folder.

As dropbox doesn't add the current directory it's using as a user variable
you'd have to get it from
C:\Users\THECURRENTUSER\AppData\Roaming\Dropbox\host.db (The location would be different on XP)
which is in BASE64 format, and then make it as a user variable
but if the user ever changes the dropbox directory you're fecked

So you'd have to just get it from the host.db and use it but you'd probably need
to check it on each run to make sure it hasn't changed

https://www.dropbox.com/votebox/1059/add-dropbox-as-an-envirionment-variable-for-windows
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

MrTAToad

PLATFORMINFO$ would be the more appropriate place for getting locations of things.  There is already "TEMP" there...


spacefractal

But not for example dropbox user variable. Here its would been nice if SETCURRENTDIR could check for that. You can allways use string variable to set the path back again eventuelly.

Temp was also a example to (even its can been checked, but I do not use that). Property it's a inline thing.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Kitty Hello

When you enter "set" in a cmd.exe, is there a dropbox variable?
That could be read with getenv$

MrTAToad

Unfortunately DropBox doesn't create a system variable...

spacefractal

#6
Its me that is stupid  =D.

Of course #DROPBOX# just launch Dropbox.exe and all its does is of course launch explorer with its path. Nothing special. Here I just got confuction its was setup a variable. But howover sadly there is no system variable, which I find is dumb.

Howover I do could find a way to find and open host.db and I just need to base64 decode it (no expert, but the download link I found is down) and find its default url (if its exists of course).

Howover list of system variable using set did help where I could locate AppData/Roaming folder.

PS. I did created my own base64 decoder. its was pretty much very easy, dispite missing num2bin$ as well bin2dec (but there is allready functions doing it). I Post it later when I have got it to work in the code snippes. Its might take a week or two or sometime. But I will open DROPBOX integration when done (more than just Windows).
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

hardyx

#7
Quote from: spacefractal on 2012-Aug-16
Howover I do could find a way to find and open host.db and I just need to base64 decode it (no expert, but the download link I found is down) and find its default url (if its exists of course).

There is no regkey for the dropbox folder :(. But, you are right, if you decode with Base64 the second line in %AppData%\Dropbox\host.db you get the dropbox folder path. This is only for Windows, of course.

kanonet

@Spacefractal: maybe you could ask moru if he can reupload his great base64 code, so you dont need to do the work again. Too bad his website is down, lets hope he has an backup. I just have an copy of his encode function, but not of the decode one in my archiv.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Moru

Ofcourse I have backups. I'm just tired of fighting with this hosting company. I'll attach the file including some example of sharing a file over a webserver with PHP and MySQL (I think, old files :-)

I don't have time to check that it actually works in the new GLBasic versions, please let me know how it goes for you!

[attachment deleted by admin]

spacefractal

I allready created base64 decoder and its was plain simple to do.

i would and try use dropbox for gamesave sync for greedy mouse, so you could play the game and resume on any device.

The hard part me guess is andriod version, due no call from c++ to java yet.

When I a day got it to work with comply of platform I add to code snippet.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

spacefractal

But I do can't take account others would do the same, so it's better to find and decode host.db
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

This gives a good idea of how to find it.  Unfortunately SQLite needs to be used...

https://forums.dropbox.com/topic.php?id=10551

spacefractal

its easier to extract it from host.db, much easier.

Since I think DROPBOX would been excellent to been include in GLBASIC, this thread should rename as a Dropbox integration project (Im not sure I should rename, so I leave it as its are). Here is what I came with to detect the folder of it, and eventuelly create the subfolder:

Code (glbasic) Select

GLOBAL DROPBOXDIR$=""
GLOBAL DROPBOXLOCALFOLDER$="GreedyMouse_SaveData"
GLOBAL DROPBOXAPPKEY$=""
GLOBAL DROPBOXSECRETKEY$=""

FUNCTION Dropbox_Init:
IF PLATFORMINFO$("")="WIN32"
LOCAL file$=GETENV$("APPDATA")+"/dropbox/host.db"
file$=REPLACE$(file$, CHR$(134), "/")
IF DOESFILEEXIST(file$)
LOCAL ok=OPENFILE(1, file$, 1)
IF ok
LOCAL line$
WHILE ENDOFFILE(1)=0
READLINE 1, line$
line$=BASE64Decode$(line$)
IF LEN(line$)>10
IF DOESDIREXIST(line$)
DROPBOXDIR$=line$
DROPBOXDIR$=REPLACE$(DROPBOXDIR$, "\\", "/")
BREAK
ENDIF
ENDIF
WEND
ENDIF
ENDIF
file$=REPLACE$(file$, "\\", "/")
ENDIF
IF DROPBOXLOCALFOLDER$<>""
IF DOESDIREXIST(DROPBOXDIR$+"/"+DROPBOXLOCALFOLDER$)=0
CREATEDIR(DROPBOXDIR$+"/"+DROPBOXLOCALFOLDER$)
ENDIF
ENDIF

DEBUG "Dropbox Folder: "+DROPBOXDIR$
ENDFUNCTION

FUNCTION Dropbox_Upload: LocalFile$, CloudFile$
ENDFUNCTION

FUNCTION Dropbox_Download: CloudFile$, LocalFile$
ENDFUNCTION

FUNCTION BASE64Decode$: String$
LOCAL keyStr$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
LOCAL result$=""
LOCAL a$, b$, c$, d$

FOR i=0 TO LEN(String$)
a$=MID$(String$, i, 1)
IF INSTR(keyStr$, a$, 0)>-1 THEN result$=result$+a$
NEXT

String$=result$
LOCAL strresult$=""
FOR i=0 TO LEN(String$) STEP 4
a$=MID$(String$, i, 1);
IF a$<>"="
LOCAL a=INSTR(keyStr$, a$, 0); a$=Bin$(a, 1); a$=RIGHT$(a$, 6)
b$=MID$(String$, i+1, 1);
IF b$<>"="
LOCAL b=INSTR(keyStr$, b$, 0); b$=Bin$(b, 1); b$=RIGHT$(b$, 6)
c$=MID$(String$, i+2, 1);
IF c$<>"="
LOCAL c=INSTR(keyStr$, c$, 0); c$=Bin$(c, 1); c$=RIGHT$(c$, 6)
d$=MID$(String$, i+3, 1);

IF d$<>"="
LOCAL d=INSTR(keyStr$, d$, 0); d$=Bin$(d, 1); d$=RIGHT$(d$, 6)
ENDIF
ENDIF
ENDIF
ENDIF
result$=a$+b$+c$+d$
LOCAL ch1$=MID$(result$, 0, 8); ch1$=Bin2Dec(ch1$); IF INTEGER(ch1$)<255 AND INTEGER(ch1$)>32 THEN strresult$=strresult$+CHR$(INTEGER(ch1$))
LOCAL ch2$=MID$(result$, 8, 8); ch2$=Bin2Dec(ch2$); IF INTEGER(ch2$)<255 AND INTEGER(ch2$)>32 THEN strresult$=strresult$+CHR$(INTEGER(ch2$))
LOCAL ch3$=MID$(result$, 16, 8); ch3$=Bin2Dec(ch3$); IF INTEGER(ch3$)<255 AND INTEGER(ch3$)>32 THEN strresult$=strresult$+CHR$(INTEGER(ch3$))

a$=""; b$=""; c$=""; d$=""
NEXT
RETURN strresult$
ENDFUNCTION

FUNCTION Bin$: p_num, p_bytes = 4
   LOCAL l_length = p_bytes * 8, l_counter, l_result$
   FOR l_counter = l_length - 1 TO 0 STEP -1
      IF bAND(p_num,POW(2, l_counter))
         l_result$ = l_result$ + "1"
      ELSE
         l_result$ = l_result$ + "0"
      ENDIF
   NEXT
   RETURN l_result$
ENDFUNCTION

FUNCTION Bin2Dec: binnum$
LOCAL l_result, l_counter, l_length
l_length = LEN(binnum$) - 1
FOR l_counter = l_length TO 0 STEP -1
IF MID$(binnum$, l_counter, 1) = 1
INC l_result, POW(2, l_length - l_counter)
ENDIF
NEXT
RETURN l_result
ENDFUNCTION


The goal is of course is get it to work on so many platforms as possible. I think savegame integration across platforms would been very cool to have (later its could go for iCloud for mac as well).

PS. Thread is renamed as i see, that pretty nice. I hope to see and do more code. Today I did some work on the waterpart in the game (also nothing dropbox today). The part works now.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad