コード例 #1
0
 public AsyncZipLoadData(string zipFileName, ModelLoadingManager.OnModelLoadedDel loadedCallback)
 {
     this.zipFileName    = zipFileName;
     this.loadedCallback = loadedCallback;
     modelFiles          = new List <string>();
     xmlFiles            = new List <string>();
 }
コード例 #2
0
 public AsyncModelLoadData(string filename, ModelLoadingManager.OnModelLoadedDel loadedCallback, ModelLoadingManager.LoadFailedCallback onFailCallback, PrintDetails.ObjectDetails objectDetails)
 {
     this.filename       = filename;
     this.loadedCallback = loadedCallback;
     this.objectDetails  = objectDetails;
     this.onFailCallback = onFailCallback;
 }
コード例 #3
0
        private bool LoadModelIntoPrinter(string filename, ModelLoadingManager.OnModelLoadedDel loadedCallback, ModelLoadingManager.LoadFailedCallback onFailCallback, PrintDetails.ObjectDetails objectDetails)
        {
            if (new SplitFileName(filename).ext.ToLowerInvariant() == "zip")
            {
                return(LoadZip(filename, loadedCallback, onFailCallback));
            }

            if (xmlPrinterSettingsZipFileLoaded)
            {
                printerview.ResetControlState();
                xmlPrinterSettingsZipFileLoaded = false;
            }
            return(ImportModel(filename, loadedCallback, onFailCallback, objectDetails));
        }
コード例 #4
0
        private bool ImportModel(string filename, ModelLoadingManager.OnModelLoadedDel loadedCallback, ModelLoadingManager.LoadFailedCallback onFailCallback, PrintDetails.ObjectDetails objectDetails)
        {
            IncFilesLoading();
            try
            {
                long num = 0;
                using (var streamReader = new StreamReader(filename))
                {
                    num = streamReader.BaseStream.Length;
                }

                if (num > 10485760L)
                {
                    informationbox.AddMessageToQueue("Fairly complex and may slow down this program");
                }

                M3D.Graphics.Ext3D.ModelRendering.Model model = printerview.GetModel(filename);
                if (model == null)
                {
                    var state = new ModelLoadingManager.AsyncModelLoadData(filename, loadedCallback, onFailCallback, objectDetails);
                    if (settings.CurrentAppearanceSettings.ShowRemoveModelWarning && printerview.ModelLoaded && (objectDetails == null || objectDetails.printerSettingsXMLFile == null || objectDetails.printerViewXMLFile == null))
                    {
                        DecFilesLoading();
                        messagebox.AddXMLMessageToQueue(new PopupMessageBox.MessageDataXML(new SpoolerMessage(), Resources.removeModelDialog, new PopupMessageBox.XMLButtonCallback(RemoveModelButtonCallback), state));
                        return(true);
                    }
                    if (printerview.ModelLoaded && !settings.CurrentAppearanceSettings.UseMultipleModels)
                    {
                        printerview.RemovePrintableModels();
                    }

                    StartLoadModelThread(state);
                }
                else
                {
                    modelLoadedQueue.Enqueue(new ModelLoadingManager.ModelLoadDetails(model, objectDetails));
                }
            }
            catch (Exception ex)
            {
                DecFilesLoading();
                ShowFileLoadingExeption(ex, filename, onFailCallback);
                return(false);
            }
            return(true);
        }
コード例 #5
0
        private void LoadZipWorkerThread(object state)
        {
            var asyncZipLoadData = state as ModelLoadingManager.AsyncZipLoadData;
            var zipFileName      = asyncZipLoadData.zipFileName;

            ModelLoadingManager.OnModelLoadedDel loadedCallback = asyncZipLoadData.loadedCallback;
            try
            {
                foreach (ZipEntry entry in asyncZipLoadData.zf)
                {
                    if (entry.IsFile)
                    {
                        byte[] buffer = new byte[4096];
                        using (FileStream fileStream = File.Create(Path.Combine(asyncZipLoadData.extractTo, Path.GetFileName(entry.Name))))
                        {
                            StreamUtils.Copy(asyncZipLoadData.zf.GetInputStream(entry), fileStream, buffer);
                        }
                    }
                }
                var settingsFromList1 = FindXMLSettingsFromList(asyncZipLoadData.xmlFiles, null, "printerview.xml");
                var settingsFromList2 = FindXMLSettingsFromList(asyncZipLoadData.xmlFiles, null, "printersettings.xml");
                if (asyncZipLoadData.xmlFiles.Count == 2 && !string.IsNullOrEmpty(settingsFromList1) && !string.IsNullOrEmpty(settingsFromList2))
                {
                    LoadPrinterView(settingsFromList1, settingsFromList2, asyncZipLoadData.extractTo, zipFileName);
                }
                else
                {
                    foreach (var modelFile in asyncZipLoadData.modelFiles)
                    {
                        var withoutExtension  = Path.GetFileNameWithoutExtension(modelFile);
                        var settingsFromList3 = FindXMLSettingsFromList(asyncZipLoadData.xmlFiles, withoutExtension, "printerview.xml");
                        var settingsFromList4 = FindXMLSettingsFromList(asyncZipLoadData.xmlFiles, withoutExtension, "printersettings.xml");
                        ImportModel(modelFile, loadedCallback, new ModelLoadingManager.LoadFailedCallback(OnPrinterViewModelLoadFailed), new PrintDetails.ObjectDetails(modelFile, settingsFromList3, settingsFromList4, zipFileName));
                    }
                }
            }
            catch (Exception ex)
            {
            }
            asyncZipLoadData.zf.Close();
            DecFilesLoading();
        }
コード例 #6
0
        private bool LoadZip(string zipFileName, ModelLoadingManager.OnModelLoadedDel loadedCallback, ModelLoadingManager.LoadFailedCallback onFailCallback)
        {
            IncFilesLoading();
            var        asyncZipLoadData = new ModelLoadingManager.AsyncZipLoadData(zipFileName, loadedCallback);
            FileStream file;

            try
            {
                file = File.OpenRead(zipFileName);
            }
            catch (IOException ex)
            {
                DecFilesLoading();
                ShowFileLoadingExeption(ex, zipFileName, onFailCallback);
                return(false);
            }
            try
            {
                asyncZipLoadData.zf        = new ZipFile(file);
                asyncZipLoadData.iconFile  = null;
                asyncZipLoadData.extractTo = Path.Combine(Paths.PublicDataFolder, "ExtractedZipFiles", Path.GetFileNameWithoutExtension(zipFileName));
                foreach (ZipEntry zipEntry in asyncZipLoadData.zf)
                {
                    if (zipEntry.IsFile)
                    {
                        var str = Path.Combine(asyncZipLoadData.extractTo, Path.GetFileName(zipEntry.Name));
                        if (ModelLoadingManager.GetModelLoader(zipEntry.Name) != null)
                        {
                            asyncZipLoadData.modelFiles.Add(str);
                        }
                        else if (zipEntry.Name.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
                        {
                            asyncZipLoadData.xmlFiles.Add(str);
                        }
                        else if (zipEntry.Name.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || zipEntry.Name.EndsWith(".png", StringComparison.OrdinalIgnoreCase) || zipEntry.Name.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase))
                        {
                            asyncZipLoadData.iconFile = str;
                        }
                    }
                }
                if (asyncZipLoadData.modelFiles.Count > 0)
                {
                    if (asyncZipLoadData.xmlFiles.Count > 0)
                    {
                        printerview.RemovePrintableModels();
                        xmlPrinterSettingsZipFileLoaded = true;
                    }
                    if (!Directory.Exists(asyncZipLoadData.extractTo))
                    {
                        Directory.CreateDirectory(asyncZipLoadData.extractTo);
                    }
                }
            }
            catch (Exception ex)
            {
                file.Close();
                DecFilesLoading();
                return(false);
            }
            if (asyncZipLoadData.modelFiles.Count > 0)
            {
                libraryview.RecentModels.CopyAndAssignIconForLibrary(zipFileName, asyncZipLoadData.iconFile);
                ThreadPool.QueueUserWorkItem(new WaitCallback(LoadZipWorkerThread), asyncZipLoadData);
                return(true);
            }
            file.Close();
            DecFilesLoading();
            return(false);
        }