Loading GUI configuration file is abnormal

pull/1857/head
2dust 3 years ago
parent 933d3c2678
commit 839d07870c

@ -41,7 +41,12 @@ namespace v2rayN.Forms
private void MainForm_Load(object sender, EventArgs e) private void MainForm_Load(object sender, EventArgs e)
{ {
ConfigHandler.LoadConfig(ref config); if (ConfigHandler.LoadConfig(ref config) != 0)
{
UI.ShowWarning($"Loading GUI configuration file is abnormal,please restart the application{Environment.NewLine}加载GUI配置文件异常,请重启应用");
Environment.Exit(0);
return;
}
ConfigHandler.InitBuiltinRouting(ref config); ConfigHandler.InitBuiltinRouting(ref config);
MainFormHandler.Instance.BackupGuiNConfig(config, true); MainFormHandler.Instance.BackupGuiNConfig(config, true);
v2rayHandler = new V2rayHandler(); v2rayHandler = new V2rayHandler();

@ -32,6 +32,15 @@ namespace v2rayN.Handler
//转成Json //转成Json
config = Utils.FromJson<Config>(result); config = Utils.FromJson<Config>(result);
} }
else
{
if (File.Exists(Utils.GetPath(configRes)))
{
Utils.SaveLog("LoadConfig Exception");
return -1;
}
}
if (config == null) if (config == null)
{ {
config = new Config config = new Config

@ -47,8 +47,9 @@ namespace v2rayN
result = reader.ReadToEnd(); result = reader.ReadToEnd();
} }
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
return result; return result;
} }
@ -69,8 +70,9 @@ namespace v2rayN
result = reader.ReadToEnd(); result = reader.ReadToEnd();
} }
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
return result; return result;
} }
@ -108,8 +110,9 @@ namespace v2rayN
Formatting.Indented, Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
return result; return result;
} }
@ -141,8 +144,9 @@ namespace v2rayN
} }
result = 0; result = 0;
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
result = -1; result = -1;
} }
return result; return result;
@ -155,8 +159,10 @@ namespace v2rayN
JObject obj = JObject.Parse(strJson); JObject obj = JObject.Parse(strJson);
return obj; return obj;
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
return null; return null;
} }
} }
@ -182,8 +188,9 @@ namespace v2rayN
return string.Join(",", lst.ToArray()); return string.Join(",", lst.ToArray());
} }
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
return string.Empty; return string.Empty;
} }
} }
@ -199,8 +206,9 @@ namespace v2rayN
str = str.Replace(Environment.NewLine, ""); str = str.Replace(Environment.NewLine, "");
return new List<string>(str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); return new List<string>(str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
return new List<string>(); return new List<string>();
} }
} }
@ -265,8 +273,9 @@ namespace v2rayN
{ {
return Convert.ToInt32(obj); return Convert.ToInt32(obj);
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
return 0; return 0;
} }
} }
@ -277,8 +286,9 @@ namespace v2rayN
{ {
return (obj == null ? string.Empty : obj.ToString()); return (obj == null ? string.Empty : obj.ToString());
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
return string.Empty; return string.Empty;
} }
} }
@ -395,8 +405,9 @@ namespace v2rayN
int var1 = ToInt(oText); int var1 = ToInt(oText);
return true; return true;
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
return false; return false;
} }
} }
@ -538,8 +549,9 @@ namespace v2rayN
string exePath = GetExePath(); string exePath = GetExePath();
RegWriteValue(autoRunRegPath, autoRunName, run ? $"\"{exePath}\"" : ""); RegWriteValue(autoRunRegPath, autoRunName, run ? $"\"{exePath}\"" : "");
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
} }
@ -558,8 +570,9 @@ namespace v2rayN
return true; return true;
} }
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
return false; return false;
} }
@ -608,8 +621,9 @@ namespace v2rayN
return value; return value;
} }
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
finally finally
{ {
@ -633,8 +647,9 @@ namespace v2rayN
regKey?.SetValue(name, value); regKey?.SetValue(name, value);
} }
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
finally finally
{ {
@ -674,8 +689,9 @@ namespace v2rayN
} }
} }
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
return -1; return -1;
} }
return roundtripTime; return roundtripTime;
@ -697,8 +713,9 @@ namespace v2rayN
lstIPAddress.Add(ipa.ToString()); lstIPAddress.Add(ipa.ToString());
} }
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
return lstIPAddress; return lstIPAddress;
} }
@ -729,8 +746,9 @@ namespace v2rayN
FileVersionInfo.GetVersionInfo(location).FileVersion.ToString(), FileVersionInfo.GetVersionInfo(location).FileVersion.ToString(),
File.GetLastWriteTime(location).ToString("yyyy/MM/dd")); File.GetLastWriteTime(location).ToString("yyyy/MM/dd"));
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
return string.Empty; return string.Empty;
} }
} }
@ -773,8 +791,9 @@ namespace v2rayN
} }
return strData; return strData;
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
return strData; return strData;
} }
@ -804,8 +823,9 @@ namespace v2rayN
{ {
return Guid.NewGuid().ToString("D"); return Guid.NewGuid().ToString("D");
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
} }
return string.Empty; return string.Empty;
} }
@ -823,8 +843,9 @@ namespace v2rayN
//WindowsBuiltInRole可以枚举出很多权限例如系统用户、User、Guest等等 //WindowsBuiltInRole可以枚举出很多权限例如系统用户、User、Guest等等
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator); return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
} }
catch catch (Exception ex)
{ {
SaveLog(ex.Message, ex);
return false; return false;
} }
} }
@ -963,7 +984,10 @@ namespace v2rayN
} }
} }
} }
catch { } catch (Exception ex)
{
SaveLog(ex.Message, ex);
}
return string.Empty; return string.Empty;
} }

Loading…
Cancel
Save