|
6 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
7 | 7 | */
|
8 | 8 |
|
| 9 | +using System; |
9 | 10 | using System.Collections.Generic;
|
| 11 | +using System.Linq; |
10 | 12 | using SafeExamBrowser.Settings;
|
11 | 13 | using SafeExamBrowser.Settings.Security;
|
12 | 14 |
|
@@ -36,6 +38,9 @@ internal override void Map(string key, object value, AppSettings settings)
|
36 | 38 | case Keys.Security.ReconfigurationUrl:
|
37 | 39 | MapReconfigurationUrl(settings, value);
|
38 | 40 | break;
|
| 41 | + case Keys.Security.VersionRestrictions: |
| 42 | + MapVersionRestrictions(settings, value); |
| 43 | + break; |
39 | 44 | }
|
40 | 45 | }
|
41 | 46 |
|
@@ -133,5 +138,35 @@ private void MapReconfigurationUrl(AppSettings settings, object value)
|
133 | 138 | settings.Security.ReconfigurationUrl = url;
|
134 | 139 | }
|
135 | 140 | }
|
| 141 | + |
| 142 | + private void MapVersionRestrictions(AppSettings settings, object value) |
| 143 | + { |
| 144 | + if (value is IList<object> restrictions) |
| 145 | + { |
| 146 | + foreach (var restriction in restrictions.Cast<string>()) |
| 147 | + { |
| 148 | + var parts = restriction.Split('.'); |
| 149 | + var os = parts.Length > 0 ? parts[0] : default; |
| 150 | + |
| 151 | + if (os?.Equals("win", StringComparison.OrdinalIgnoreCase) == true) |
| 152 | + { |
| 153 | + var major = parts.Length > 1 ? int.Parse(parts[1]) : default; |
| 154 | + var minor = parts.Length > 2 ? int.Parse(parts[2]) : default; |
| 155 | + var patch = parts.Length > 3 && int.TryParse(parts[3], out _) ? int.Parse(parts[3]) : default(int?); |
| 156 | + var build = parts.Length > 4 && int.TryParse(parts[4], out _) ? int.Parse(parts[4]) : default(int?); |
| 157 | + |
| 158 | + settings.Security.VersionRestrictions.Add(new VersionRestriction |
| 159 | + { |
| 160 | + Major = major, |
| 161 | + Minor = minor, |
| 162 | + Patch = patch, |
| 163 | + Build = build, |
| 164 | + IsMinimumRestriction = restriction.Contains("min"), |
| 165 | + RequiresAllianceEdition = restriction.Contains("AE") |
| 166 | + }); |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + } |
136 | 171 | }
|
137 | 172 | }
|
0 commit comments