-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting on bg threads because of RoInitialize
- Loading branch information
1 parent
b65069d
commit 85f8767
Showing
4 changed files
with
59 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch potatodrive", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "./cmd/main" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ import ( | |
"runtime" | ||
"unsafe" | ||
|
||
"github.com/go-ole/go-ole" | ||
"github.com/saltosystems/winrt-go" | ||
Check failure on line 8 in win/cfapi/filesystem/register.go GitHub Actions / build
|
||
"github.com/saltosystems/winrt-go/windows/foundation" | ||
Check failure on line 9 in win/cfapi/filesystem/register.go GitHub Actions / build
|
||
"github.com/saltosystems/winrt-go/windows/storage" | ||
Check failure on line 10 in win/cfapi/filesystem/register.go GitHub Actions / build
|
||
"github.com/saltosystems/winrt-go/windows/storage/provider" | ||
Check failure on line 11 in win/cfapi/filesystem/register.go GitHub Actions / build
|
||
) | ||
|
@@ -13,14 +16,31 @@ func getFolder(folder string) (*storage.IStorageFolder, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
semaphore := make(chan bool) | ||
iid := winrt.ParameterizedInstanceGUID(foundation.GUIDAsyncOperationCompletedHandler, storage.SignatureStorageFolder) | ||
handler := foundation.NewAsyncOperationCompletedHandler(ole.NewGUID(iid), func(instance *foundation.AsyncOperationCompletedHandler, asyncInfo *foundation.IAsyncOperation, asyncStatus foundation.AsyncStatus) { | ||
semaphore <- true | ||
}) | ||
err = op.SetCompleted(handler) | ||
if err != nil { | ||
return nil, err | ||
} | ||
<-semaphore | ||
ptr, err := op.GetResults() | ||
return (*storage.IStorageFolder)(unsafe.Pointer(ptr)), err | ||
} | ||
|
||
func RegisterRootPath(id string, rootPath string) error { | ||
runtime.LockOSThread() | ||
defer runtime.UnlockOSThread() | ||
var info provider.StorageProviderSyncRootInfo | ||
err := ole.RoInitialize(1) | ||
if err != nil { | ||
return err | ||
} | ||
info, err := provider.NewStorageProviderSyncRootInfo() | ||
if err != nil { | ||
return err | ||
} | ||
folder, err := getFolder(rootPath) | ||
if err != nil { | ||
return err | ||
|
@@ -30,28 +50,28 @@ func RegisterRootPath(id string, rootPath string) error { | |
if err == nil && existing != nil { | ||
// Already registered | ||
eid, _ := existing.GetId() | ||
if eid == id { | ||
/*if eid == id { | ||
// No need to register again | ||
return nil | ||
} else { | ||
// unregister first | ||
err = provider.StorageProviderSyncRootManagerUnregister(eid) | ||
if err != nil { | ||
return err | ||
} | ||
} else {*/ | ||
// unregister first | ||
err = provider.StorageProviderSyncRootManagerUnregister(eid) | ||
if err != nil { | ||
return err | ||
} | ||
//} | ||
} | ||
|
||
info.SetAllowPinning(true) | ||
info.SetId(id) | ||
info.SetPath(folder) | ||
info.SetDisplayNameResource("PotatoDrive " + rootPath) | ||
info.SetIconResource("potato.ico") | ||
info.SetIconResource("C:\\git\\potatodrive\\potato.ico") | ||
info.SetVersion("1") | ||
info.SetHydrationPolicy(provider.StorageProviderHydrationPolicyFull) | ||
info.SetHydrationPolicyModifier(provider.StorageProviderHydrationPolicyModifierAutoDehydrationAllowed) | ||
info.SetPopulationPolicy(provider.StorageProviderPopulationPolicyAlwaysFull) | ||
info.SetInSyncPolicy(provider.StorageProviderInSyncPolicyDirectoryLastWriteTime | provider.StorageProviderInSyncPolicyFileLastWriteTime) | ||
info.SetHardlinkPolicy(provider.StorageProviderHardlinkPolicyNone) | ||
return provider.StorageProviderSyncRootManagerRegister(&info) | ||
return provider.StorageProviderSyncRootManagerRegister(info) | ||
} |