public static Primitive GetPrimitiveInfo(LDDEnvironment environment, int partID) { if (environment.DatabaseExtracted) { var primitivesDir = Path.Combine(environment.ApplicationDataPath, "db\\Primitives"); var primitiveFile = Path.Combine(primitivesDir, $"{partID}.xml"); if (!File.Exists(primitiveFile)) { throw new FileNotFoundException($"Primitive file not found. ({partID}.xml)"); } return(Primitive.Load(primitiveFile)); } else { using (var lif = LifFile.Open(Path.Combine(environment.ApplicationDataPath, "db.lif"))) { var primitiveFolder = lif.GetFolder("Primitives"); var meshesFolder = primitiveFolder.GetFolder("LOD0"); var primitiveEntry = primitiveFolder.GetFile($"{partID}.xml"); if (primitiveEntry == null) { throw new FileNotFoundException($"Primitive file not found. ({partID}.xml)"); } return(Primitive.Load(primitiveEntry.GetStream())); } } }
private static PaletteFile GetLddPaletteFile(LDDEnvironment environment) { var appDataPalettes = environment.GetAppDataSubDir("Palettes"); if (File.Exists(Path.Combine(appDataPalettes, "LDD.lif"))) { return(PaletteFile.FromLif(Path.Combine(appDataPalettes, "LDD.lif"))); } if (Directory.Exists(Path.Combine(appDataPalettes, "LDD"))) { return(PaletteFile.FromDirectory(Path.Combine(appDataPalettes, "LDD"))); } string dbLifPath = environment.GetLifFilePath(LddLif.DB); if (File.Exists(dbLifPath)) { using (var lif = LifFile.Open(dbLifPath)) { var paletteEntry = lif.GetAllFiles().FirstOrDefault(x => x.Name == "LDD.lif"); if (paletteEntry != null) { using (var paletteLif = LifFile.Read(paletteEntry.GetStream())) return(PaletteFile.FromLif(paletteLif)); } } } return(null); }
public static PartWrapper LoadPart(LDDEnvironment environment, int partID, bool loadMeshes) { if (environment.DatabaseExtracted) { var primitivesDir = environment.GetAppDataSubDir("db\\Primitives"); return(GetPartFromDirectory(primitivesDir, partID, loadMeshes)); } else { using (var lif = LifFile.Open(environment.GetLifFilePath(LddLif.DB))) return(GetPartFromLif(lif, partID, loadMeshes)); } }
public LifContentWrapper(CacheSource source, string path) { Source = source; if (source == CacheSource.LIF) { Lif = LifFile.Open(path); } else { PrimitiveDir = new DirectoryInfo(path); } }
private void ExtractLif(LDD.LddLif lif) { try { var tmpEnv = new LDD.LDDEnvironment(PrgmFilePathTextBox.Value, AppDataPathTextBox.Value); string lifFilePath = tmpEnv.GetLifFilePath(lif); string lifFolderPath = tmpEnv.GetLifFolderPath(lif); if (!string.IsNullOrEmpty(lifFilePath) && File.Exists(lifFilePath)) { using (var lifFile = LifFile.Open(lifFilePath)) lifFile.ExtractTempTo(lifFolderPath); } //LifFile.Open() } catch { } }
public void ImportLddParts() { NotifyBeginStep("Importing LDD parts and elements"); NotifyIndefiniteProgress(); NotifyProgressStatus("Clearing previous data..."); using (var trans = Connection.BeginTransaction()) using (var cmd = Connection.CreateCommand()) { cmd.CommandText = $"DELETE FROM {DbHelper.GetTableName<LddPart>()}"; cmd.ExecuteNonQuery(); cmd.CommandText = $"DELETE FROM sqlite_sequence WHERE name='{DbHelper.GetTableName<LddPart>()}'"; cmd.ExecuteNonQuery(); trans.Commit(); } string tmpFolder1 = null, tmpFolder2 = null; try { //Extract Primitives and Assemblies if needed if (!Environment.DatabaseExtracted) { NotifyProgressStatus("Extracting primitives and assemblies from 'db.lif'"); string dbLifPath = Environment.GetLifFilePath(LddLif.DB); if (!File.Exists(dbLifPath)) { return; } using (var dbLif = LifFile.Open(dbLifPath)) { var primitivesFolder = dbLif.GetFolder("Primitives"); var assembliesFolder = dbLif.GetFolder("Assemblies"); if (primitivesFolder == null || assembliesFolder == null) { return; } tmpFolder1 = FileHelper.GetTempDirectory(); primitivesFolder.ExtractContent(tmpFolder1, CancellationToken, null); if (IsCancellationRequested) { return; } tmpFolder2 = FileHelper.GetTempDirectory(); assembliesFolder.ExtractContent(tmpFolder2, CancellationToken, null); } } if (IsCancellationRequested) { return; } string primitivesDir = tmpFolder1 ?? Environment.GetAppDataSubDir("db\\Primitives"); ImportPrimitivesFromDirectory(primitivesDir); if (IsCancellationRequested) { return; } string assembliesDir = tmpFolder1 ?? Environment.GetAppDataSubDir("db\\Assemblies"); ImportAssembliesFromDirectory(assembliesDir); if (IsCancellationRequested) { return; } } finally { if (!string.IsNullOrEmpty(tmpFolder1)) { Task.Factory.StartNew(() => FileHelper.DeleteFileOrFolder(tmpFolder1, true, true)); } if (!string.IsNullOrEmpty(tmpFolder2)) { Task.Factory.StartNew(() => FileHelper.DeleteFileOrFolder(tmpFolder2, true, true)); } } }