1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
| '*******************************************************************************
'Populates the OneDrive providers in the 'm_providers' structure
'Utility for 'GetOneDriveLocalPath' and 'GetOneDriveWebPath'
'*******************************************************************************
Private Sub ReadODProviders(ByVal rebuildCache As Boolean)
Dim i As Long
Dim accountsInfo As ONEDRIVE_ACCOUNTS_INFO
Dim FileName As String
Static collTrackedFiles As Collection
Const oneSecond As Date = 1 / 86400
'
If Not rebuildCache And m_providers.isSet Then
If m_providers.lastCacheUpdate + oneSecond > Now() Then Exit Sub
Dim v As Variant
For Each v In collTrackedFiles
If Len(Dir(v)) > 0 Then ' Vérifie si le fichier existe
Debug.Print v
If FileDateTime(v) > m_providers.lastCacheUpdate Then
rebuildCache = True
Exit For
End If
Else
' Gérer l'erreur ou l'absence de fichier
Debug.Print "Fichier non trouvé : " & v
End If
If FileDateTime(v) > m_providers.lastCacheUpdate Then
rebuildCache = True
Exit For
End If
Next v
If Not rebuildCache Then
m_providers.lastCacheUpdate = Now()
Exit Sub
End If
End If
'
m_providers.pCount = 0
m_providers.isSet = False
'
ReadODAccountsInfo accountsInfo
If Not accountsInfo.isSet Then Exit Sub
'
#If Mac Then 'Grant access to all needed files/folders, in batch
Dim collFiles As New Collection
'
For i = 1 To accountsInfo.pCount
With accountsInfo.arr(i)
collFiles.Add .iniPath
collFiles.Add .datPath
collFiles.Add .dbPath
collFiles.Add .clientPath
collFiles.Add .globalPath
If .isPersonal Then
collFiles.Add .groupPath
Else
FileName = Dir(Replace(.clientPath, ".ini", "_*.ini"))
Do While LenB(FileName) > 0
collFiles.Add .folderPath & "/" & FileName
FileName = Dir
Loop
End If
End With
Next i
'
Const syncIDFileName As String = ".849C9593-D756-4E56-8D6E-42412F2A707B"
Dim collCloudDirs As Collection: Set collCloudDirs = GetODCloudDirs()
Dim odCloudDir As Variant
Dim arrPaths() As String
Dim syncID As String
Dim folderPath As String
Dim collSyncIDToDir As New Collection
'
For Each odCloudDir In collCloudDirs
collFiles.Add odCloudDir
collFiles.Add odCloudDir & "/" & syncIDFileName
Next odCloudDir
arrPaths = CollectionToStrings(collFiles)
If Not GrantAccessToMultipleFiles(arrPaths) Then Exit Sub
'
Set collFiles = New Collection
For Each odCloudDir In collCloudDirs
syncID = ReadSyncID(odCloudDir & "/" & syncIDFileName)
If LenB(syncID) > 0 Then
collSyncIDToDir.Add odCloudDir, syncID
Else
FileName = Dir(odCloudDir & "/", vbDirectory)
Do While LenB(FileName) > 0
folderPath = odCloudDir & "/" & FileName
collFiles.Add folderPath
collFiles.Add folderPath & "/" & syncIDFileName
FileName = Dir
Loop
End If
Next odCloudDir
If collFiles.Count > 0 Then
arrPaths = CollectionToStrings(collFiles)
If Not GrantAccessToMultipleFiles(arrPaths) Then Exit Sub
'
For i = LBound(arrPaths) To UBound(arrPaths) Step 2
syncID = ReadSyncID(arrPaths(i + 1))
If LenB(syncID) > 0 Then collSyncIDToDir.Add arrPaths(i), syncID
Next i
End If
#End If
For i = 1 To accountsInfo.pCount 'Check for unsynchronized accounts
Dim j As Long
For j = i + 1 To accountsInfo.pCount
ValidateAccounts accountsInfo.arr(i), accountsInfo.arr(j)
Next j
Next i
Set collTrackedFiles = New Collection
For i = 1 To accountsInfo.pCount
With accountsInfo.arr(i)
If .isValid Then
If .isPersonal Then
AddPersonalProviders accountsInfo.arr(i)
collTrackedFiles.Add .groupPath
Else
AddBusinessProviders accountsInfo.arr(i)
FileName = Dir(Replace(.clientPath, ".ini", "_*.ini"))
Do While LenB(FileName) > 0
collTrackedFiles.Add .folderPath & "/" & FileName
FileName = Dir
Loop
End If
If .hasDatFile Then
collTrackedFiles.Add .datPath
Else
collTrackedFiles.Add .dbPath
End If
collTrackedFiles.Add .clientPath
collTrackedFiles.Add .globalPath
collTrackedFiles.Add .iniPath
End If
End With
Next i
#If Mac Then
If collSyncIDToDir.Count > 0 Then 'Replace sandbox paths
For i = 1 To m_providers.pCount
With m_providers.arr(i)
On Error Resume Next
.syncDir = collSyncIDToDir(.syncID)
.mountPoint = Replace(.mountPoint, .baseMount, .syncDir)
On Error GoTo 0
End With
Next i
End If
#End If
m_providers.isSet = True
m_providers.lastCacheUpdate = Now()
#If Mac Then
ClearConversionDescriptors
#End If
End Sub |
Partager