corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) 2006-2014, openmetaverse.org |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * - Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * |
||
8 | * - Redistributions of source code must retain the above copyright notice, this |
||
9 | * list of conditions and the following disclaimer. |
||
10 | * - Neither the name of the openmetaverse.org nor the names |
||
11 | * of its contributors may be used to endorse or promote products derived from |
||
12 | * this software without specific prior written permission. |
||
13 | * |
||
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
24 | * POSSIBILITY OF SUCH DAMAGE. |
||
25 | */ |
||
26 | |||
27 | using System; |
||
28 | using System.Collections.Generic; |
||
29 | using System.Text; |
||
30 | using OpenMetaverse.StructuredData; |
||
31 | using System.IO; |
||
32 | |||
33 | namespace WinGridProxy |
||
34 | { |
||
35 | internal class FilterEntryOptions |
||
36 | { |
||
37 | public string Type { get; set; } |
||
38 | public bool Checked { get; set; } |
||
39 | public string Group { get; set; } |
||
40 | } |
||
41 | |||
42 | internal class SettingsStore |
||
43 | { |
||
44 | private const int FileVersion = 1; |
||
45 | |||
46 | public Dictionary<string, FilterEntryOptions> MessageSessions; |
||
47 | public Dictionary<string, FilterEntryOptions> PacketSessions; |
||
48 | public bool StatisticsEnabled; |
||
49 | public bool SaveSessionOnExit; |
||
50 | public bool AutoCheckNewCaps; |
||
51 | |||
52 | public SettingsStore() |
||
53 | { |
||
54 | MessageSessions = new Dictionary<string, FilterEntryOptions>(); |
||
55 | PacketSessions = new Dictionary<string, FilterEntryOptions>(); |
||
56 | } |
||
57 | |||
58 | public OSDMap Serialize() |
||
59 | { |
||
60 | OSDMap map = new OSDMap(); |
||
61 | if (MessageSessions.Count > 0) |
||
62 | { |
||
63 | OSDArray messageArray = new OSDArray(MessageSessions.Count); |
||
64 | foreach (KeyValuePair<string, FilterEntryOptions> kvp in MessageSessions) |
||
65 | { |
||
66 | OSDMap sessionMap = new OSDMap(4); |
||
67 | sessionMap["Name"] = OSD.FromString(kvp.Key); |
||
68 | sessionMap["Type"] = OSD.FromString(kvp.Value.Type); |
||
69 | sessionMap["Capture"] = OSD.FromBoolean(kvp.Value.Checked); |
||
70 | sessionMap["Group"] = OSD.FromString(kvp.Value.Group); |
||
71 | messageArray.Add(sessionMap); |
||
72 | } |
||
73 | map.Add("message_sessions", messageArray); |
||
74 | } |
||
75 | |||
76 | if (PacketSessions.Count > 0) |
||
77 | { |
||
78 | OSDArray packetArray = new OSDArray(PacketSessions.Count); |
||
79 | foreach (KeyValuePair<string, FilterEntryOptions> kvp in PacketSessions) |
||
80 | { |
||
81 | OSDMap sessionMap = new OSDMap(4); |
||
82 | sessionMap["Name"] = OSD.FromString(kvp.Key); |
||
83 | sessionMap["Type"] = OSD.FromString(kvp.Value.Type); |
||
84 | sessionMap["Capture"] = OSD.FromBoolean(kvp.Value.Checked); |
||
85 | sessionMap["Group"] = OSD.FromString(kvp.Value.Group); |
||
86 | packetArray.Add(sessionMap); |
||
87 | } |
||
88 | map.Add("packet_sessions", packetArray); |
||
89 | } |
||
90 | |||
91 | map.Add("CaptureStatistics", OSD.FromBoolean(StatisticsEnabled)); |
||
92 | map.Add("SaveProfileOnExit", OSD.FromBoolean(SaveSessionOnExit)); |
||
93 | map.Add("AutoCheckNewCaps", OSD.FromBoolean(AutoCheckNewCaps)); |
||
94 | map.Add("FileVersion", OSD.FromInteger(FileVersion)); |
||
95 | return map; |
||
96 | } |
||
97 | |||
98 | public void Deserialize(OSDMap map) |
||
99 | { |
||
100 | MessageSessions.Clear(); |
||
101 | PacketSessions.Clear(); |
||
102 | |||
103 | if (map.ContainsKey("FileVersion") && map["FileVersion"].AsInteger() == FileVersion) |
||
104 | { |
||
105 | StatisticsEnabled = map["CaptureStatistics"].AsBoolean(); |
||
106 | SaveSessionOnExit = map["SaveProfileOnExit"].AsBoolean(); |
||
107 | AutoCheckNewCaps = map["AutoCheckNewCaps"].AsBoolean(); |
||
108 | } |
||
109 | else |
||
110 | { |
||
111 | Console.WriteLine("Error loading saved settings, FileVersion is null or out of date."); |
||
112 | StatisticsEnabled = true; |
||
113 | AutoCheckNewCaps = true; |
||
114 | SaveSessionOnExit = true; |
||
115 | return; |
||
116 | } |
||
117 | |||
118 | if (map.ContainsKey("message_sessions")) |
||
119 | { |
||
120 | OSDArray messageArray = (OSDArray)map["message_sessions"]; |
||
121 | |||
122 | //MessageSessions = new Dictionary<string, FilterEntryOptions>(messageArray.Count); |
||
123 | |||
124 | for (int i = 0; i < messageArray.Count; i++) |
||
125 | { |
||
126 | OSDMap sessionsMap = (OSDMap)messageArray[i]; |
||
127 | FilterEntryOptions entry = new FilterEntryOptions(); |
||
128 | entry.Checked = sessionsMap["Capture"].AsBoolean(); |
||
129 | entry.Group = sessionsMap["Group"].AsString(); |
||
130 | entry.Type = sessionsMap["Type"].AsString(); |
||
131 | MessageSessions.Add(sessionsMap["Name"].AsString(), entry); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | if (map.ContainsKey("packet_sessions")) |
||
136 | { |
||
137 | OSDArray packetArray = (OSDArray)map["packet_sessions"]; |
||
138 | |||
139 | //PacketSessions = new Dictionary<string, FilterEntryOptions>(packetArray.Count); |
||
140 | |||
141 | for (int i = 0; i < packetArray.Count; i++) |
||
142 | { |
||
143 | OSDMap packetMap = (OSDMap)packetArray[i]; |
||
144 | FilterEntryOptions entry = new FilterEntryOptions(); |
||
145 | entry.Checked = packetMap["Capture"].AsBoolean(); |
||
146 | entry.Group = packetMap["Group"].AsString(); |
||
147 | entry.Type = packetMap["Type"].AsString(); |
||
148 | PacketSessions.Add(packetMap["Name"].AsString(), entry); |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | |||
153 | public bool DeserializeFromFile(string fileName) |
||
154 | { |
||
155 | if (File.Exists(fileName)) |
||
156 | { |
||
157 | try |
||
158 | { |
||
159 | OSDMap map = (OSDMap)OSDParser.DeserializeLLSDNotation(File.ReadAllText(fileName)); |
||
160 | this.Deserialize(map); |
||
161 | return true; |
||
162 | } |
||
163 | catch (Exception e) |
||
164 | { |
||
165 | Console.WriteLine("Exception Deserializing From File: {0} {1}", e.Message, e.StackTrace); |
||
166 | } |
||
167 | } |
||
168 | return false; |
||
169 | } |
||
170 | |||
171 | public void SerializeToFile(string fileName) |
||
172 | { |
||
173 | File.WriteAllText(fileName, this.Serialize().ToString()); |
||
174 | } |
||
175 | } |
||
176 | } |