mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-14 20:29:07 +00:00
fix possible crash (?) due to DateTime format
This commit is contained in:
@@ -64,9 +64,16 @@ namespace QuickLook.Common.Helpers
|
|||||||
private static T GetSettingFromXml<T>(XmlDocument doc, string id, T failsafe)
|
private static T GetSettingFromXml<T>(XmlDocument doc, string id, T failsafe)
|
||||||
{
|
{
|
||||||
var v = doc.SelectSingleNode($@"/Settings/{id}");
|
var v = doc.SelectSingleNode($@"/Settings/{id}");
|
||||||
var result = v == null ? failsafe : (T) Convert.ChangeType(v.InnerText, typeof(T));
|
|
||||||
|
|
||||||
return result;
|
try
|
||||||
|
{
|
||||||
|
var result = v == null ? failsafe : (T) Convert.ChangeType(v.InnerText, typeof(T));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return failsafe;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteSettingToXml(XmlDocument doc, string id, object value)
|
private static void WriteSettingToXml(XmlDocument doc, string id, object value)
|
||||||
@@ -81,7 +88,7 @@ namespace QuickLook.Common.Helpers
|
|||||||
{
|
{
|
||||||
var node = doc.CreateNode(XmlNodeType.Element, id, doc.NamespaceURI);
|
var node = doc.CreateNode(XmlNodeType.Element, id, doc.NamespaceURI);
|
||||||
node.InnerText = value.ToString();
|
node.InnerText = value.ToString();
|
||||||
doc.SelectSingleNode(@"/Settings").AppendChild(node);
|
doc.SelectSingleNode(@"/Settings")?.AppendChild(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.Save(new Uri(doc.BaseURI).LocalPath);
|
doc.Save(new Uri(doc.BaseURI).LocalPath);
|
||||||
@@ -97,7 +104,22 @@ namespace QuickLook.Common.Helpers
|
|||||||
CreateNewConfig(file);
|
CreateNewConfig(file);
|
||||||
|
|
||||||
var doc = new XmlDocument();
|
var doc = new XmlDocument();
|
||||||
doc.Load(file);
|
try
|
||||||
|
{
|
||||||
|
doc.Load(file);
|
||||||
|
}
|
||||||
|
catch (XmlException)
|
||||||
|
{
|
||||||
|
CreateNewConfig(file);
|
||||||
|
doc.Load(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doc.SelectSingleNode(@"/Settings") == null)
|
||||||
|
{
|
||||||
|
CreateNewConfig(file);
|
||||||
|
doc.Load(file);
|
||||||
|
}
|
||||||
|
|
||||||
FileCache.Add(file, doc);
|
FileCache.Add(file, doc);
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
@@ -110,6 +132,8 @@ namespace QuickLook.Common.Helpers
|
|||||||
writer.WriteStartElement("Settings");
|
writer.WriteStartElement("Settings");
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
writer.WriteEndDocument();
|
writer.WriteEndDocument();
|
||||||
|
|
||||||
|
writer.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -88,11 +88,11 @@ namespace QuickLook
|
|||||||
|
|
||||||
private void CheckUpdate()
|
private void CheckUpdate()
|
||||||
{
|
{
|
||||||
if (DateTime.Now - SettingHelper.Get<DateTime>("LastUpdate") < TimeSpan.FromDays(7))
|
if (DateTime.Now.Ticks - SettingHelper.Get<long>("LastUpdateTicks") < TimeSpan.FromDays(7).Ticks)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Task.Delay(120 * 1000).ContinueWith(_ => Updater.CheckForUpdates(true));
|
Task.Delay(120 * 1000).ContinueWith(_ => Updater.CheckForUpdates(true));
|
||||||
SettingHelper.Set("LastUpdate", DateTime.Now);
|
SettingHelper.Set("LastUpdateTicks", DateTime.Now.Ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoteCallShowPreview(StartupEventArgs e)
|
private void RemoteCallShowPreview(StartupEventArgs e)
|
||||||
|
Reference in New Issue
Block a user