| 1 | #Region "Microsoft.VisualBasic::c369f5afcfff60a489e3386afa259933, Microsoft.VisualBasic.Core\ApplicationServices\Debugger\Config.vb" |
| 2 | |
| 3 | ' Author: |
| 4 | ' |
| 5 | ' asuka (amethyst.asuka@gcmodeller.org) |
| 6 | ' xie (genetics@smrucc.org) |
| 7 | ' xieguigang (xie.guigang@live.com) |
| 8 | ' |
| 9 | ' Copyright (c) 2018 GPL3 Licensed |
| 10 | ' |
| 11 | ' |
| 12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
| 13 | ' |
| 14 | ' |
| 15 | ' This program is free software: you can redistribute it and/or modify |
| 16 | ' it under the terms of the GNU General Public License as published by |
| 17 | ' the Free Software Foundation, either version 3 of the License, or |
| 18 | ' (at your option) any later version. |
| 19 | ' |
| 20 | ' This program is distributed in the hope that it will be useful, |
| 21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | ' GNU General Public License for more details. |
| 24 | ' |
| 25 | ' You should have received a copy of the GNU General Public License |
| 26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | |
| 28 | |
| 29 | |
| 30 | ' /********************************************************************************/ |
| 31 | |
| 32 | ' Summaries: |
| 33 | |
| 34 | ' Class Config |
| 35 | ' |
| 36 | ' Properties: DefaultFile, level, mute |
| 37 | ' |
| 38 | ' Function: Load, Save, ToString |
| 39 | ' |
| 40 | ' |
| 41 | ' /********************************************************************************/ |
| 42 | |
| 43 | #End Region |
| 44 | |
| 45 | Imports Microsoft.VisualBasic.Serialization.JSON |
| 46 | |
| 47 | Namespace ApplicationServices.Debugging |
| 48 | |
| 49 | Public Class Config |
| 50 | |
| 51 | Public Property level As DebuggerLevels = DebuggerLevels.On |
| 52 | Public Property mute As Boolean = False |
| 53 | |
| 54 | Public Shared ReadOnly Property DefaultFile As String = |
| 55 | App.LocalData & "/debugger-config.json" |
| 56 | |
| 57 | Public Shared Function Load() As Config |
| 58 | Try |
| 59 | Dim cfg As Config = |
| 60 | IO.File.ReadAllText(DefaultFile).LoadJSON(Of Config) |
| 61 | |
| 62 | If cfg Is Nothing Then |
| 63 | Return New Config().Save() |
| 64 | Else |
| 65 | Return cfg |
| 66 | End If |
| 67 | Catch ex As Exception When Not DefaultFile.FileExists |
| 68 | Return New Config().Save() |
| 69 | Catch ex As Exception |
| 70 | Call App.LogException(ex) |
| 71 | |
| 72 | ' 假若是多进程的并行计算任务,则可能会出现默认配置文件被占用的情况, |
| 73 | ' 这个也无能为力了, 只能够放弃读取, 直接使用默认的调试器参数 |
| 74 | Return New Config |
| 75 | End Try |
| 76 | End Function |
| 77 | |
| 78 | Private Function Save() As Config |
| 79 | Call Me.GetJson.SaveTo(DefaultFile) |
| 80 | Return Me |
| 81 | End Function |
| 82 | |
| 83 | Public Overrides Function ToString() As String |
| 84 | Return Me.GetJson |
| 85 | End Function |
| 86 | End Class |
| 87 | End Namespace |