It is currently Thu Jan 28, 2021 2:46 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Get path of the Google Drive folder
PostPosted: Mon Dec 16, 2019 8:24 pm 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3967
Location: Berlin, Germany
Hi,

for some programs it is useful to know the location of the Google Drive folder on a given system.
(see also my tip "Get path of the Dropbox folder")

Unfortunately I have no opportunity to test this code under Mac OS. So I would highly appreciate it if someone else would do so. :-)

Code:
; Code successfully tested with Google Backup and Sync 3.47
; and
; [v] PB 5.71 LTS (x64)
; on
; [v] Windows 10 Pro, version 1903
; [ ] Mac OS


CompilerIf #PB_Compiler_IsMainFile
   EnableExplicit
CompilerEndIf


Procedure.s GoogleDriveFolder ()
   ; -- return the main folder used by "Google Backup and Sync" client,
   ;    with trailing path separator, or "" if not found
   ; after <https://stackoverflow.com/questions/12173077/how-do-i-programmatically-locate-my-google-drive-folder-using-c>
   Protected.i db, i
   Protected dbFile$, query$, ret$=""
   
   CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
         dbFile$ = GetEnvironmentVariable("localappdata") + "\Google\Drive\user_default\sync_config.db"
         
      CompilerCase #PB_OS_MacOS
         ; after <https://stackoverflow.com/questions/30609133/how-do-i-programmatically-locate-my-google-drive-folder-in-osx>
         ; (not yet tested)
         dbFile$ = "~/Library/Application Support/Google/Drive/user_default/sync_config.db"
         
      CompilerCase #PB_OS_Linux
         CompilerError "Sorry, GoogleDriveFolder() is not supported on Linux"
         
         ; In contrast to Windows and OSX, for Linux there is no official
         ; "Google Backup and Sync" client. One proposed solution is to
         ; integrate Google Drive using Gnome Online Accounts, see e.g.
         ; <https://www.itzgeek.com/how-tos/linux/linux-mint-how-tos/how-to-integrate-google-drive-on-linux-mint-19-tara.html>.
         ; However, this does not work on my Linux Mint 19.2 (x64) system.
         ;
         ; There are several third party Linux programs for synchronisation
         ; with Google Drive. The name and location of the corresponding
         ; folder depends on the particular program, so it's not possible
         ; to provide a general solution here.
   CompilerEndSelect
   
   db = OpenDatabase(#PB_Any, dbFile$, "", "", #PB_Database_SQLite)
   If db
      query$ = "SELECT * FROM data WHERE entry_key='local_sync_root_path'"
      If DatabaseQuery(db, query$)
         If NextDatabaseRow(db)
            i = DatabaseColumnIndex(db, "data_value")
            ret$ = GetDatabaseString(db, i)
            If FileSize(ret$) <> -2          ; If 'ret$' is not an existing folder
               ret$ = ""
            EndIf   
         EndIf
         FinishDatabaseQuery(db)
      EndIf
      CloseDatabase(db)
   EndIf
   
   If Asc(ret$) <> '' And Right(ret$, 1) <> #PS$
      ret$ + #PS$
   EndIf
   ProcedureReturn Mid(ret$, 5)   ; discard leading "\\?\"
EndProcedure


CompilerIf #PB_Compiler_IsMainFile
   ; -- Demo
   
   UseSQLiteDatabase()
   
   Define GoogleDrive$ = GoogleDriveFolder()
   
   Debug "Location of Google Drive folder:"
   If Asc(GoogleDrive$) <> ''
      Debug "'" + GoogleDrive$ + "'"
   Else
      Debug "not found"
   EndIf
CompilerEndIf

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye