From 0b73017250b4e284d39d69cc647b728e86e0da7b Mon Sep 17 00:00:00 2001 From: Simon Dong Date: Thu, 14 Jan 2016 00:01:06 +0800 Subject: [PATCH] create statistics file if not exists. --- .../Service/AvailabilityStatistics.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs index 8f2e6eaa..94cbd735 100644 --- a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs +++ b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs @@ -258,9 +258,20 @@ namespace Shadowsocks.Controller Logging.Debug($"loading statistics from {path}"); if (!File.Exists(path)) { - Console.WriteLine($"statistics file does not exist, try to reload {RetryInterval / 60 / 1000} minutes later"); - _timer.Change(RetryInterval, Interval); - return; + try { + using (FileStream fs = File.Create(path)) + { + //do nothing + } + }catch(Exception e) + { + Logging.LogUsefulException(e); + } + if (!File.Exists(path)) { + Console.WriteLine($"statistics file does not exist, try to reload {RetryInterval / 60 / 1000} minutes later"); + _timer.Change(RetryInterval, Interval); + return; + } } RawStatistics = (from l in File.ReadAllLines(path).Skip(1) let strings = l.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)