Skip to content

Commit b13844b

Browse files
committed
Add check for OneDrive folders as they cannot be compressed. Closes #411
1 parent 152e564 commit b13844b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

CompactGUI.Core/SharedMethods.vb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Public Module SharedMethods
1111
ElseIf folder.Contains((Environment.GetFolderPath(Environment.SpecialFolder.Windows))) Then : Return (False, "Cannot compress system directory")
1212
ElseIf folder.EndsWith(":\") Then : Return (False, "Cannot compress root directory")
1313
ElseIf IsDirectoryEmptySafe(folder) Then : Return (False, "This directory is either empty or you are not authorized to access its files.")
14+
ElseIf IsOneDriveFolder(folder) Then : Return (False, "Files synced with OneDrive cannot be compressed as they use a different storage structure")
1415
ElseIf DriveInfo.GetDrives().First(Function(f) folder.StartsWith(f.Name)).DriveFormat <> "NTFS" Then : Return (False, "Cannot compress a directory on a non-NTFS drive")
1516
End If
1617

@@ -110,7 +111,21 @@ Public Module SharedMethods
110111

111112
End Function
112113

114+
Function IsOneDriveFolder(folderPath As String) As Boolean
115+
Dim userProfile As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
116+
Dim oneDrivePaths As New List(Of String) From {
117+
Path.Combine(userProfile, "OneDrive"), ' Personal OneDrive
118+
Path.Combine(userProfile, "OneDrive - Personal"), ' Alternative Personal OneDrive
119+
Path.Combine(userProfile, "OneDrive for Business"), ' OneDrive for Business
120+
Path.Combine(userProfile, "OneDrive - Business") ' Alternative OneDrive for Business
121+
}
113122

123+
' Normalize the folder path to compare
124+
Dim normalizedFolderPath As String = Path.GetFullPath(folderPath).TrimEnd(Path.DirectorySeparatorChar).ToLowerInvariant()
125+
126+
' Check if the folder path starts with any of the known OneDrive paths
127+
Return oneDrivePaths.Any(Function(odPath) normalizedFolderPath.StartsWith(Path.GetFullPath(odPath).TrimEnd(Path.DirectorySeparatorChar).ToLowerInvariant()))
128+
End Function
114129

115130
#Region "DLL Imports"
116131

0 commit comments

Comments
 (0)