|
7 | 7 | usingSystem.Data.Common; |
8 | 8 | usingSystem.Diagnostics; |
9 | 9 | usingSystem.Diagnostics.CodeAnalysis; |
| 10 | +usingSystem.IO; |
10 | 11 | usingSystem.Reflection; |
| 12 | +usingSystem.Runtime.InteropServices; |
11 | 13 | usingMicrosoft.Data.Sqlite.Properties; |
12 | 14 | usingSQLitePCL; |
13 | 15 | usingstaticSQLitePCL.raw; |
@@ -52,38 +54,50 @@ static SqliteConnection() |
52 | 54 | ?.GetRuntimeMethod("Init",Type.EmptyTypes) |
53 | 55 | ?.Invoke(null,null); |
54 | 56 |
|
55 | | -varappDataType=Type.GetType("Windows.Storage.ApplicationData, Windows, ContentType=WindowsRuntime") |
56 | | -??Type.GetType("Windows.Storage.ApplicationData, Microsoft.Windows.SDK.NET"); |
57 | | - |
58 | | -varstorageFolderType=Type.GetType("Windows.Storage.StorageFolder, Windows, ContentType=WindowsRuntime") |
59 | | -??Type.GetType("Windows.Storage.StorageFolder, Microsoft.Windows.SDK.NET"); |
60 | | - |
61 | | -object?currentAppData=null; |
62 | | -try |
63 | | -{ |
64 | | -currentAppData=appDataType?.GetRuntimeProperty("Current")?.GetValue(null); |
65 | | -} |
66 | | -catch(TargetInvocationException) |
| 57 | +if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
67 | 58 | { |
68 | | -// Ignore "The process has no package identity." |
69 | | -} |
| 59 | +Type?appDataType=null; |
| 60 | +Type?storageFolderType=null; |
| 61 | +try |
| 62 | +{ |
| 63 | +appDataType=Type.GetType("Windows.Storage.ApplicationData, Windows, ContentType=WindowsRuntime") |
| 64 | +??Type.GetType("Windows.Storage.ApplicationData, Microsoft.Windows.SDK.NET"); |
70 | 65 |
|
71 | | -if(currentAppData!=null) |
72 | | -{ |
73 | | -varlocalFolder=appDataType?.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData); |
74 | | -varlocalFolderPath=(string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(localFolder); |
75 | | -if(localFolderPath!=null) |
| 66 | +storageFolderType=Type.GetType("Windows.Storage.StorageFolder, Windows, ContentType=WindowsRuntime") |
| 67 | +??Type.GetType("Windows.Storage.StorageFolder, Microsoft.Windows.SDK.NET"); |
| 68 | +} |
| 69 | +catch(FileLoadException) |
76 | 70 | { |
77 | | -varrc=sqlite3_win32_set_directory(SQLITE_WIN32_DATA_DIRECTORY_TYPE,localFolderPath); |
78 | | -Debug.Assert(rc==SQLITE_OK); |
| 71 | +// Ignore "Could not load assembly." |
79 | 72 | } |
80 | 73 |
|
81 | | -vartempFolder=appDataType?.GetRuntimeProperty("TemporaryFolder")?.GetValue(currentAppData); |
82 | | -vartempFolderPath=(string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(tempFolder); |
83 | | -if(tempFolderPath!=null) |
| 74 | +object?currentAppData=null; |
| 75 | +try |
84 | 76 | { |
85 | | -varrc=sqlite3_win32_set_directory(SQLITE_WIN32_TEMP_DIRECTORY_TYPE,tempFolderPath); |
86 | | -Debug.Assert(rc==SQLITE_OK); |
| 77 | +currentAppData=appDataType?.GetRuntimeProperty("Current")?.GetValue(null); |
| 78 | +} |
| 79 | +catch(TargetInvocationException) |
| 80 | +{ |
| 81 | +// Ignore "The process has no package identity." |
| 82 | +} |
| 83 | + |
| 84 | +if(currentAppData!=null) |
| 85 | +{ |
| 86 | +varlocalFolder=appDataType?.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData); |
| 87 | +varlocalFolderPath=(string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(localFolder); |
| 88 | +if(localFolderPath!=null) |
| 89 | +{ |
| 90 | +varrc=sqlite3_win32_set_directory(SQLITE_WIN32_DATA_DIRECTORY_TYPE,localFolderPath); |
| 91 | +Debug.Assert(rc==SQLITE_OK); |
| 92 | +} |
| 93 | + |
| 94 | +vartempFolder=appDataType?.GetRuntimeProperty("TemporaryFolder")?.GetValue(currentAppData); |
| 95 | +vartempFolderPath=(string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(tempFolder); |
| 96 | +if(tempFolderPath!=null) |
| 97 | +{ |
| 98 | +varrc=sqlite3_win32_set_directory(SQLITE_WIN32_TEMP_DIRECTORY_TYPE,tempFolderPath); |
| 99 | +Debug.Assert(rc==SQLITE_OK); |
| 100 | +} |
87 | 101 | } |
88 | 102 | } |
89 | 103 | } |
|