public string GetDataPathOrDefault(string key, string defaultValue) { if (key != null && _contentDataPaths.ContainsKey(key.ToLower())) { if (_contentDataPaths[key.ToLower()].AbsolutePath != null) { return(_contentDataPaths[key.ToLower()].AbsolutePath); } if (_contentDataPaths[key.ToLower()].ZipFilePath != null) { var tempContentFile = TempfileUtil.NewFilename(Path.GetExtension(defaultValue)); try { ZipTools.ExtractZipFileToFile(_contentDataPaths[key.ToLower()].ZipFilePath, null, _contentDataPaths[key.ToLower()].ReferencePath, tempContentFile); return(tempContentFile); } catch (Exception ex) { // ignore errors, keep on trucking just like SE. // write event log warning of any files not loaded. DiagnosticsLogging.LogWarning(string.Format(Res.ExceptionState_CorruptModFile, _contentDataPaths[key.ToLower()].ZipFilePath), ex); return(defaultValue); } } } return(defaultValue); }
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { var comException = e.Exception as System.Runtime.InteropServices.COMException; if (comException != null && comException.ErrorCode == -2147221040) { // To fix 'OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN)' // http://stackoverflow.com/questions/12769264/openclipboard-failed-when-copy-pasting-data-from-wpf-datagrid e.Handled = true; return; } // Log details to Application Event Log. DiagnosticsLogging.LogException(e.Exception); string message; if (e.Exception is ToolboxException) { message = e.Exception.Message; } else { // Unhandled Exception. if (DiagnosticsLogging.LoggingSourceExists()) { message = string.Format(Res.DialogUnhandledExceptionEventMessage, e.Exception.Message); } else { message = string.Format(Res.DialogUnhandledExceptionMessage, e.Exception.Message); } } MessageBox.Show(message, String.Format(Res.DialogUnhandledExceptionTitle, GlobalSettings.GetAppVersion()), MessageBoxButton.OK, MessageBoxImage.Error); TempfileUtil.Dispose(); e.Handled = true; if (Application.Current != null) { Application.Current.Shutdown(); } }
private MyObjectBuilder_Definitions LoadAllDefinitionsZip(string stockContentPath, string zipModFile, ref Dictionary <string, ContentDataPath> contentData) { var zipFiles = ZipTools.ExtractZipContentList(zipModFile, null); var definitions = new MyObjectBuilder_Definitions(); if (!zipFiles.Any(f => Path.GetDirectoryName(f).Equals("Data", StringComparison.InvariantCultureIgnoreCase))) { return(definitions); } var files = zipFiles.Where(f => Path.GetDirectoryName(f).Equals("Data", StringComparison.InvariantCultureIgnoreCase) && Path.GetExtension(f).Equals(".sbc", StringComparison.InvariantCultureIgnoreCase)).ToArray(); foreach (var filePath in files) { MyObjectBuilder_Definitions stockTemp = null; try { using (var stream = ZipTools.ExtractZipFileToSteam(zipModFile, null, filePath)) { stockTemp = SpaceEngineersApi.ReadSpaceEngineersFile <MyObjectBuilder_Definitions>(stream); } } catch (Exception ex) { // ignore errors, keep on trucking just like SE. // write event log warning of any files not loaded. DiagnosticsLogging.LogWarning(string.Format(Res.ExceptionState_CorruptContentFile, filePath), ex); } if (stockTemp != null) { MergeDefinitions(ref definitions, stockTemp); } } LoadContent(stockContentPath, null, zipModFile, zipFiles, definitions, ref contentData); return(definitions); }
private MyObjectBuilder_Definitions LoadAllDefinitions(string stockContentPath, string modContentPath, ref Dictionary <string, ContentDataPath> contentData) { var searchPath = Path.Combine(modContentPath, "Data"); var definitions = new MyObjectBuilder_Definitions(); if (!Directory.Exists(searchPath)) { return(definitions); } var files = Directory.GetFiles(searchPath, "*.sbc"); foreach (var filePath in files) { MyObjectBuilder_Definitions stockTemp = null; try { bool isCompressed; stockTemp = SpaceEngineersApi.ReadSpaceEngineersFile <MyObjectBuilder_Definitions>(filePath, out isCompressed); } catch (Exception ex) { // ignore errors, keep on trucking just like SE. // write event log warning of any files not loaded. DiagnosticsLogging.LogWarning(string.Format(Res.ExceptionState_CorruptContentFile, filePath), ex); } if (stockTemp != null) { MergeDefinitions(ref definitions, stockTemp); } } LoadContent(stockContentPath, modContentPath, null, null, definitions, ref contentData); return(definitions); }
private static void UninstallConfigurationSettings() { DiagnosticsLogging.RemoveLog(); CleanBinCache(); }
private static void InstallConfigurationSettings() { DiagnosticsLogging.CreateLog(); CleanBinCache(); }