@@ -78,10 +78,14 @@ public class LLMUnitySetup
78
78
public static string LlamaLibURL = $ "https://github.com/undreamai/LlamaLib/releases/download/{ LlamaLibVersion } /undreamai-{ LlamaLibVersion } -llamacpp.zip";
79
79
/// <summary> LlamaLib path </summary>
80
80
public static string libraryPath = GetAssetPath ( Path . GetFileName ( LlamaLibURL ) . Replace ( ".zip" , "" ) ) ;
81
+ /// <summary> LLMnity store path </summary>
82
+ public static string LLMUnityStore = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "LLMUnity" ) ;
81
83
/// <summary> Model download path </summary>
82
- public static string modelDownloadPath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "LLMUnity " ) ;
84
+ public static string modelDownloadPath = Path . Combine ( LLMUnityStore , "models " ) ;
83
85
/// <summary> Model list for project </summary>
84
86
public static string modelListPath = Path . Combine ( Application . temporaryCachePath , "modelCache.json" ) ;
87
+ /// <summary> Temporary dir for build </summary>
88
+ public static string buildTempDir = Path . Combine ( Application . temporaryCachePath , "LLMUnityBuild" ) ;
85
89
86
90
/// <summary> Default models for download </summary>
87
91
[ HideInInspector ] public static readonly ( string , string ) [ ] modelOptions = new ( string , string ) [ ]
@@ -228,11 +232,11 @@ public static async Task AndroidExtractFile(string assetName, bool overwrite = f
228
232
string target = GetAssetPath ( assetName ) ;
229
233
if ( ! overwrite && File . Exists ( target ) )
230
234
{
231
- Debug . Log ( $ "File { target } already exists") ;
235
+ Log ( $ "File { target } already exists") ;
232
236
return ;
233
237
}
234
238
235
- Debug . Log ( $ "Extracting { source } to { target } ") ;
239
+ Log ( $ "Extracting { source } to { target } ") ;
236
240
237
241
// UnityWebRequest to read the file from StreamingAssets
238
242
UnityWebRequest www = UnityWebRequest . Get ( source ) ;
@@ -242,7 +246,7 @@ public static async Task AndroidExtractFile(string assetName, bool overwrite = f
242
246
while ( ! operation . isDone ) await Task . Delay ( 1 ) ;
243
247
if ( www . result != UnityWebRequest . Result . Success )
244
248
{
245
- Debug . LogError ( "Failed to load file from StreamingAssets: " + www . error ) ;
249
+ LogError ( "Failed to load file from StreamingAssets: " + www . error ) ;
246
250
}
247
251
else
248
252
{
@@ -267,6 +271,44 @@ public static bool IsSubPath(string childPath, string parentPath)
267
271
}
268
272
269
273
#if UNITY_EDITOR
274
+
275
+ public static void CopyPath ( string source , string target )
276
+ {
277
+ if ( File . Exists ( source ) )
278
+ {
279
+ File . Copy ( source , target ) ;
280
+ }
281
+ else if ( Directory . Exists ( source ) )
282
+ {
283
+ Directory . CreateDirectory ( target ) ;
284
+ List < string > filesAndDirs = new List < string > ( ) ;
285
+ filesAndDirs . AddRange ( Directory . GetFiles ( source ) ) ;
286
+ filesAndDirs . AddRange ( Directory . GetDirectories ( source ) ) ;
287
+ foreach ( string path in filesAndDirs )
288
+ {
289
+ CopyPath ( path , Path . Combine ( target , Path . GetFileName ( path ) ) ) ;
290
+ }
291
+ }
292
+ }
293
+
294
+ public static void MovePath ( string source , string target )
295
+ {
296
+ CopyPath ( source , target ) ;
297
+ DeletePath ( source ) ;
298
+ }
299
+
300
+ public static bool DeletePath ( string path )
301
+ {
302
+ if ( ! IsSubPath ( path , GetAssetPath ( ) ) && ! IsSubPath ( path , buildTempDir ) )
303
+ {
304
+ LogError ( $ "Safeguard: { path } will not be deleted because it may not be safe") ;
305
+ return false ;
306
+ }
307
+ if ( File . Exists ( path ) ) File . Delete ( path ) ;
308
+ else if ( Directory . Exists ( path ) ) Directory . Delete ( path , true ) ;
309
+ return true ;
310
+ }
311
+
270
312
[ HideInInspector ] public static float libraryProgress = 1 ;
271
313
272
314
private static async Task DownloadLibrary ( )
@@ -277,7 +319,9 @@ private static async Task DownloadLibrary()
277
319
if ( ! Directory . Exists ( libraryPath ) )
278
320
{
279
321
await DownloadFile ( LlamaLibURL , libZip , true , null , SetLibraryProgress ) ;
322
+ AssetDatabase . StartAssetEditing ( ) ;
280
323
ZipFile . ExtractToDirectory ( libZip , libraryPath ) ;
324
+ AssetDatabase . StopAssetEditing ( ) ;
281
325
File . Delete ( libZip ) ;
282
326
}
283
327
libraryProgress = 1 ;
@@ -307,26 +351,6 @@ public static string AddAsset(string assetPath)
307
351
return filename ;
308
352
}
309
353
310
- public static void CreateSymlink ( string sourcePath , string targetPath )
311
- {
312
- bool isDirectory = Directory . Exists ( sourcePath ) ;
313
- if ( ! isDirectory && ! File . Exists ( sourcePath ) ) throw new FileNotFoundException ( $ "Source path does not exist: { sourcePath } ") ;
314
-
315
- bool success ;
316
- #if UNITY_STANDALONE_WIN
317
- success = CreateSymbolicLink ( targetPath , sourcePath , ( int ) isDirectory ) ;
318
- #else
319
- success = symlink ( sourcePath , targetPath ) == 0 ;
320
- #endif
321
- if ( ! success ) throw new IOException ( $ "Failed to create symbolic link: { targetPath } ") ;
322
- }
323
-
324
- [ DllImport ( "kernel32.dll" , CharSet = CharSet . Unicode ) ]
325
- private static extern bool CreateSymbolicLink ( string lpSymlinkFileName , string lpTargetFileName , int dwFlags ) ;
326
-
327
- [ DllImport ( "libc" , SetLastError = true ) ]
328
- private static extern int symlink ( string oldpath , string newpath ) ;
329
-
330
354
#endif
331
355
/// \endcond
332
356
public static int GetMaxFreqKHz ( int cpuId )
@@ -422,7 +446,7 @@ public static int AndroidGetNumBigCores()
422
446
}
423
447
catch ( Exception e )
424
448
{
425
- Debug . LogError ( e . Message ) ;
449
+ LogError ( e . Message ) ;
426
450
}
427
451
428
452
int numBigCores = 0 ;
@@ -474,7 +498,7 @@ public static int AndroidGetNumBigCoresCapacity()
474
498
}
475
499
catch ( Exception e )
476
500
{
477
- Debug . LogError ( e . Message ) ;
501
+ LogError ( e . Message ) ;
478
502
}
479
503
480
504
int numBigCores = 0 ;
0 commit comments