33using System . Net . Http ;
44using System . Threading . Tasks ;
55using System . Collections . Generic ;
6+ using System . IO . Compression ;
7+
68
79public class Setup
810{
11+
12+ static readonly string VERSION = "0.3.14" ;
13+ static readonly string BASE_URL = $ "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v{ VERSION } ";
14+
915 static async Task Main ( string [ ] args )
1016 {
11- const string baseUrl = "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v0.3.14" ;
12- string powersyncCorePath = Path . Combine ( AppContext . BaseDirectory , "../../../../.." , "PowerSync/PowerSync.Common/" ) ;
17+ //await DesktopSetup();
18+ //await MauiIosSetup();
19+ await MauiAndroidSetup ( ) ;
20+ }
21+
22+ static async Task MauiAndroidSetup ( )
23+ {
24+ string powersyncMauiPath = Path . Combine ( AppContext . BaseDirectory , "../../../../.." , "PowerSync/PowerSync.Maui/" ) ;
25+
26+ string nativeDir = Path . Combine ( powersyncMauiPath , "Platforms" , "Android" , "jniLibs" ) ;
27+ Directory . CreateDirectory ( nativeDir ) ;
1328
29+ string aarFile = $ "powersync-sqlite-core-{ VERSION } .aar";
30+ string mavenUrl = $ "https://repo1.maven.org/maven2/co/powersync/powersync-sqlite-core/{ VERSION } /{ aarFile } ";
31+ string aarPath = Path . Combine ( nativeDir , aarFile ) ;
32+ string extractedDir = Path . Combine ( nativeDir , "extracted" ) ;
33+
34+ try
35+ {
36+ await DownloadFile ( mavenUrl , aarPath ) ;
37+
38+ if ( File . Exists ( aarPath ) )
39+ {
40+ // Clean up existing extracted directory
41+ if ( Directory . Exists ( extractedDir ) )
42+ {
43+ Directory . Delete ( extractedDir , recursive : true ) ;
44+ }
45+
46+ // Extract the AAR file (it's essentially a ZIP file)
47+ ZipFile . ExtractToDirectory ( aarPath , extractedDir ) ;
48+
49+ // Copy native libraries to the appropriate locations
50+ string jniLibsPath = Path . Combine ( extractedDir , "jni" ) ;
51+ if ( Directory . Exists ( jniLibsPath ) )
52+ {
53+ // Copy each architecture's native libraries
54+ foreach ( string archDir in Directory . GetDirectories ( jniLibsPath ) )
55+ {
56+ string archName = Path . GetFileName ( archDir ) ;
57+ string targetArchDir = Path . Combine ( nativeDir , archName ) ;
58+ Directory . CreateDirectory ( targetArchDir ) ;
59+
60+ foreach ( string libFile in Directory . GetFiles ( archDir , "*.so" ) )
61+ {
62+ string targetLibPath = Path . Combine ( targetArchDir , Path . GetFileName ( libFile ) ) ;
63+ File . Copy ( libFile , targetLibPath , overwrite : true ) ;
64+ }
65+ }
66+ }
67+
68+ // Clean up extracted directory and AAR file
69+ Directory . Delete ( extractedDir , recursive : true ) ;
70+ File . Delete ( aarPath ) ;
71+
72+ Console . WriteLine ( $ "AAR file extracted successfully from { aarFile } to native libraries in { nativeDir } ") ;
73+ }
74+ else
75+ {
76+ throw new IOException ( $ "File { aarFile } does not exist.") ;
77+ }
78+ }
79+ catch ( Exception ex )
80+ {
81+ Console . Error . WriteLine ( $ "Error processing { aarFile } : { ex . Message } ") ;
82+ }
83+ }
84+
85+ static async Task MauiIosSetup ( )
86+ {
87+ string powersyncMauiPath = Path . Combine ( AppContext . BaseDirectory , "../../../../.." , "PowerSync/PowerSync.Maui/" ) ;
88+
89+ string nativeDir = Path . Combine ( powersyncMauiPath , "Platforms" , "iOS" , "NativeLibs" ) ;
90+ Directory . CreateDirectory ( nativeDir ) ;
91+
92+ string extractedFramework = "powersync-sqlite-core.xcframework" ;
93+ string originalFile = "powersync-sqlite-core.xcframework.zip" ;
94+ string sqliteMauiPath = Path . Combine ( nativeDir , originalFile ) ;
95+ string extractedPath = Path . Combine ( nativeDir , extractedFramework ) ;
96+
97+ try
98+ {
99+ await DownloadFile ( $ "{ BASE_URL } /{ originalFile } ", sqliteMauiPath ) ;
100+
101+ if ( File . Exists ( sqliteMauiPath ) )
102+ {
103+ // Extract the ZIP file
104+ if ( Directory . Exists ( extractedPath ) )
105+ {
106+ Directory . Delete ( extractedPath , recursive : true ) ;
107+ }
108+
109+ ZipFile . ExtractToDirectory ( sqliteMauiPath , nativeDir ) ;
110+
111+ // Clean up the ZIP file
112+ File . Delete ( sqliteMauiPath ) ;
113+
114+ Console . WriteLine ( $ "File extracted successfully from { originalFile } to { extractedFramework } in { nativeDir } ") ;
115+ }
116+ else
117+ {
118+ throw new IOException ( $ "File { originalFile } does not exist.") ;
119+ }
120+ }
121+ catch ( Exception ex )
122+ {
123+ Console . Error . WriteLine ( $ "Error processing { originalFile } : { ex . Message } ") ;
124+ }
125+ }
126+
127+ static async Task DesktopSetup ( )
128+ {
129+ string powersyncCommonPath = Path . Combine ( AppContext . BaseDirectory , "../../../../.." , "PowerSync/PowerSync.Common/" ) ;
130+
14131 var runtimeIdentifiers = new Dictionary < string , ( string originalFile , string newFile ) >
15132 {
16133 { "osx-x64" , ( "libpowersync_x64.dylib" , "libpowersync.dylib" ) } ,
@@ -22,19 +139,19 @@ static async Task Main(string[] args)
22139
23140 foreach ( var ( rid , ( originalFile , newFile ) ) in runtimeIdentifiers )
24141 {
25- string nativeDir = Path . Combine ( powersyncCorePath , "runtimes" , rid , "native" ) ;
142+ string nativeDir = Path . Combine ( powersyncCommonPath , "runtimes" , rid , "native" ) ;
26143 Directory . CreateDirectory ( nativeDir ) ;
27144
28- string sqliteCorePath = Path . Combine ( nativeDir , originalFile ) ;
145+ string sqliteCommonPath = Path . Combine ( nativeDir , originalFile ) ;
29146 string newFilePath = Path . Combine ( nativeDir , newFile ) ;
30147
31148 try
32149 {
33- await DownloadFile ( $ "{ baseUrl } /{ originalFile } ", sqliteCorePath ) ;
150+ await DownloadFile ( $ "{ BASE_URL } /{ originalFile } ", sqliteCommonPath ) ;
34151
35- if ( File . Exists ( sqliteCorePath ) )
152+ if ( File . Exists ( sqliteCommonPath ) )
36153 {
37- File . Move ( sqliteCorePath , newFilePath , overwrite : true ) ;
154+ File . Move ( sqliteCommonPath , newFilePath , overwrite : true ) ;
38155 Console . WriteLine ( $ "File renamed successfully from { originalFile } to { newFile } in { nativeDir } ") ;
39156 }
40157 else
0 commit comments