Пример #1
0
        private void LoadLifFile(LifFile file)
        {
            LifTreeView.Nodes.Clear();
            FolderListView.DataSource = null;
            FolderListView.ClearObjects();
            ToolBarFolderCombo.ComboBox.DataSource = null;
            CurrentFolderItems.Clear();

            if (CurrentFile != null && CurrentFile != file)
            {
                CurrentFile.Dispose();
                CurrentFile = null;
            }

            CurrentFile   = file;
            CurrentFolder = null;
            IsNewLif      = string.IsNullOrEmpty(file?.FilePath);

            CurrentFileStripLabel.Text = file?.FilePath;

            if (file != null)
            {
                FillTreeView();
                NavigateToFolder(file.RootFolder);
                if (IsNewLif)
                {
                    EnableLifEditing();
                }
            }

            UpdateMenuItems();
        }
Пример #2
0
        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()));
                }
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
 public void Dispose()
 {
     if (Lif != null)
     {
         Lif.Dispose();
         Lif = null;
     }
 }
Пример #5
0
 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));
     }
 }
Пример #6
0
            public LifContentWrapper(CacheSource source, string path)
            {
                Source = source;

                if (source == CacheSource.LIF)
                {
                    Lif = LifFile.Open(path);
                }
                else
                {
                    PrimitiveDir = new DirectoryInfo(path);
                }
            }
Пример #7
0
 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 { }
 }
Пример #8
0
        private void StartExtraction()
        {
            CreateDestinationFolder();

            string tmpExtractDir = GetTmpExtractionDirectory();

            CancellationSource = new CancellationTokenSource();
            ExtractionStart    = DateTime.Now;
            LastestProgress    = LifFile.ExtractionProgress.Default;
            ExtractionProgressTimer.Start();
            extractProgressPanel1.BeginExtraction();

            var entriesArray = ItemsToExtract.ToArray();

            if (ExtractFolderContent)
            {
                entriesArray = (ItemsToExtract[0] as LifFile.FolderEntry).Entries.ToArray();
            }

            ExtractButton.Enabled       = false;
            DestinationGroupBox.Enabled = false;
            ProgressGroupBox.Enabled    = true;

            ExtractionTask = Task.Factory.StartNew(() =>
            {
                bool extractionSucceded = false;

                try
                {
                    LifFile.ExtractEntries(entriesArray, tmpExtractDir,
                                           CancellationSource.Token, OnExtractionProgress);
                    extractionSucceded = true;
                }
                catch
                {
                }

                BeginInvoke((Action)(() => ExtractionFinished(tmpExtractDir, extractionSucceded)));
            });
        }
Пример #9
0
        public static PartWrapper GetPartFromLif(LifFile lif, int partID, bool loadMeshes)
        {
            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)");
            }

            var surfaces = new List <PartSurfaceMesh>();

            foreach (var meshEntry in meshesFolder.GetFiles($"{partID}.g*"))
            {
                if (!PartSurfaceMesh.ParseSurfaceID(meshEntry.Name, out int surfID))
                {
                    surfID = surfaces.Count;
                }

                var surfaceInfo = new PartSurfaceMesh(partID, surfID,
                                                      loadMeshes ? MeshFile.Read(meshEntry.GetStream()) : null);
                surfaces.Add(surfaceInfo);
            }

            if (!surfaces.Any())
            {
                throw new FileNotFoundException($"Mesh file not found. ({partID}.g)");
            }

            var primitive = Primitive.Load(primitiveEntry.GetStream());

            primitive.ID = partID;
            return(new PartWrapper(primitive, surfaces)
            {
                PartID = partID
            });
        }
Пример #10
0
        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));
                }
            }
        }