Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7951fea

Browse files
authored
Microsoft.Data.Sqlite: Only try sqlite3_win32_set_directory on Windows and be more resilient
1 parentd7177e9 commit7951fea

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

‎src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs‎

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
usingSystem.Data.Common;
88
usingSystem.Diagnostics;
99
usingSystem.Diagnostics.CodeAnalysis;
10+
usingSystem.IO;
1011
usingSystem.Reflection;
12+
usingSystem.Runtime.InteropServices;
1113
usingMicrosoft.Data.Sqlite.Properties;
1214
usingSQLitePCL;
1315
usingstaticSQLitePCL.raw;
@@ -52,38 +54,50 @@ static SqliteConnection()
5254
?.GetRuntimeMethod("Init",Type.EmptyTypes)
5355
?.Invoke(null,null);
5456

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))
6758
{
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");
7065

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)
7670
{
77-
varrc=sqlite3_win32_set_directory(SQLITE_WIN32_DATA_DIRECTORY_TYPE,localFolderPath);
78-
Debug.Assert(rc==SQLITE_OK);
71+
// Ignore "Could not load assembly."
7972
}
8073

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
8476
{
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+
}
87101
}
88102
}
89103
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp