//public async void UpdateAllScripts(ScriptConfigModel selectedScript)
        //{
        //    await DownLoadScript(selectedScript.ScriptPath);
        //    selectedScript.LastCommitTime = selectedScript.PreUpdateTime.Value;
        //    selectedScript.IsUpdateAvailable = false;
        //    selectedScript.PreUpdateTime = null;
        //    UpdateScriptConfig();
        //}

        public void DeleteScript(ScriptConfigModel selectedScript)
        {
            if (File.Exists(MainViewModel.AssemblyPath + selectedScript.ScriptLocalPath))
            {
                File.Delete(MainViewModel.AssemblyPath + selectedScript.ScriptLocalPath);
            }
            ScriptsData.Remove(selectedScript);
            UpdateScriptConfig();
        }
 private async Task DownLoadSelectedPath()
 {
     IsUpdating = true;
     try
     {
         if (!string.IsNullOrEmpty(LuaPath))
         {
             if (RegExpressions.LuaRawPathRegex.Value.IsMatch(LuaPath) || RegExpressions.LuaPathRegex.Value.IsMatch(LuaPath))
             {
                 var fileName     = Path.GetFileNameWithoutExtension(LuaPath);
                 var scriptConfig = ScriptsData.FirstOrDefault(x => x.ScriptName == fileName);
                 //if (scriptConfig != null && (File.Exists($@"scripts\{fileName}.lua") || File.Exists($@"scripts\{fileName}.bak")))
                 //{
                 //    scriptConfig.ScriptPath = LuaPath;
                 //    UpdateScriptConfig();
                 //    return;
                 //}
                 if ((LuaPath.StartsWith("http://github") || LuaPath.StartsWith("https://github")) && LuaPath.Contains("blob"))
                 {
                     LuaPath = LuaPath.Replace("http://github", "https://raw.githubusercontent");
                     LuaPath = LuaPath.Replace("https://github", "http://raw.githubusercontent");
                     LuaPath = LuaPath.Replace("blob/", "");
                 }
                 LuaPath = LuaPath.Replace("https", "http");
                 fileWatcher.EnableRaisingEvents = false;
                 var isEnabled = true;
                 if (scriptConfig != null && !scriptConfig.IsEnabled)
                 {
                     isEnabled = false;
                 }
                 try
                 {
                     await DownLoadScript(LuaPath, isEnabled);
                 }
                 catch (WebException)
                 {
                     //if (scriptConfig != null)
                     //{
                     //    ScriptsData.Remove(scriptConfig);
                     //    if (File.Exists(scriptConfig.ScriptLocalPath))
                     //    {
                     //        File.Delete(scriptConfig.ScriptLocalPath);
                     //    }
                     //}
                 }
                 UpdateScriptConfig();
                 fileWatcher.EnableRaisingEvents = true;
             }
             else
             {
                 if (LuaPath.Contains("tree/master"))
                 {
                     DotaViewModel.GameBrowserVm.MainViewModel.ShowError(Properties.Resources.IncorrectLuaPath);
                     return;
                 }
                 if (LuaPath.StartsWith("http://github") || LuaPath.StartsWith("https://github"))
                 {
                     LuaPath = LuaPath.Replace("https", "http");
                     fileWatcher.EnableRaisingEvents = false;
                     var scriptConfig = ScriptsData.FirstOrDefault(x => x.RepositoryPath == LuaPath);
                     try
                     {
                         await DownLoadRepository(LuaPath);
                     }
                     catch (WebException)
                     {
                         if (scriptConfig != null)
                         {
                             ScriptsData.Remove(scriptConfig);
                             if (File.Exists(MainViewModel.AssemblyPath + scriptConfig.ScriptLocalPath))
                             {
                                 File.Delete(MainViewModel.AssemblyPath + scriptConfig.ScriptLocalPath);
                             }
                         }
                     }
                     var zipPath = $@"{scriptDir}\master.zip";
                     if (File.Exists(zipPath))
                     {
                         File.Delete(zipPath);
                     }
                     UpdateScriptConfig();
                     fileWatcher.EnableRaisingEvents = true;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         DotaViewModel.GameBrowserVm.MainViewModel.ShowError(ex.Message);
         Log.Error(ex, "null");
     }
     finally
     {
         IsUpdating = false;
         fileWatcher.EnableRaisingEvents = true;
     }
 }
 private void FileWatcherHandle(object sender, FileSystemEventArgs e)
 {
     try
     {
         if (!Regex.IsMatch(Path.GetExtension(e.FullPath), @"\.lua|\.bak", RegexOptions.IgnoreCase))
         {
             return;
         }
         if (e.ChangeType == WatcherChangeTypes.Changed)
         {
             var scriptConfig = ScriptsData.FirstOrDefault(x => x.ScriptLocalPath == e.FullPath.Replace(MainViewModel.AssemblyPath, "") && x.ScriptName == Path.GetFileNameWithoutExtension(e.Name));
             if (scriptConfig != null)
             {
                 scriptConfig.ScriptPath     = null;
                 scriptConfig.RepositoryPath = null;
                 UpdateScriptConfig();
                 return;
             }
         }
         if (e.ChangeType == WatcherChangeTypes.Renamed)
         {
             var args         = e as RenamedEventArgs;
             var isEnabled    = e.FullPath.EndsWith(".bak") ? false : true;
             var scriptConfig = ScriptsData.FirstOrDefault(x => x.ScriptLocalPath == args.OldFullPath.Replace(MainViewModel.AssemblyPath, "") && x.ScriptName == Path.GetFileNameWithoutExtension(args.OldName));
             if (scriptConfig != null)
             {
                 scriptConfig.IsEnabled       = isEnabled;
                 scriptConfig.ScriptLocalPath = args.FullPath.Replace(MainViewModel.AssemblyPath, "");
                 scriptConfig.ScriptName      = Path.GetFileNameWithoutExtension(args.Name);
                 UpdateScriptConfig();
             }
             else
             {
                 var newScriptConfig = new ScriptConfigModel
                 {
                     IsEnabled       = isEnabled,
                     ScriptLocalPath = e.FullPath.Replace(MainViewModel.AssemblyPath, ""),
                     ScriptName      = Path.GetFileNameWithoutExtension(e.Name)
                 };
                 System.Windows.Application.Current.Dispatcher.Invoke(() =>
                 {
                     ScriptsData.Add(newScriptConfig);
                 });
                 UpdateScriptConfig();
             }
             return;
         }
         if (e.ChangeType == WatcherChangeTypes.Created)
         {
             var isEnabled = e.FullPath.EndsWith(".bak") ? false : true;
             if (File.Exists(e.FullPath))
             {
                 var scriptConfig = ScriptsData.FirstOrDefault(x => x.ScriptLocalPath == e.FullPath.Replace(MainViewModel.AssemblyPath, "") && x.ScriptName == Path.GetFileNameWithoutExtension(e.Name));
                 if (scriptConfig != null)
                 {
                     scriptConfig.ScriptPath     = null;
                     scriptConfig.RepositoryPath = null;
                     UpdateScriptConfig();
                     return;
                 }
             }
             var newScriptConfig = new ScriptConfigModel
             {
                 IsEnabled       = isEnabled,
                 ScriptLocalPath = e.FullPath.Replace(MainViewModel.AssemblyPath, ""),
                 ScriptName      = Path.GetFileNameWithoutExtension(e.Name)
             };
             System.Windows.Application.Current.Dispatcher.Invoke(() =>
             {
                 ScriptsData.Add(newScriptConfig);
             });
             UpdateScriptConfig();
             return;
         }
         if (e.ChangeType == WatcherChangeTypes.Deleted)
         {
             var scriptConfig = ScriptsData.FirstOrDefault(x => x.ScriptLocalPath == e.FullPath.Replace(MainViewModel.AssemblyPath, "") && x.ScriptName == Path.GetFileNameWithoutExtension(e.Name));
             if (scriptConfig != null)
             {
                 System.Windows.Application.Current.Dispatcher.Invoke(() =>
                 {
                     ScriptsData.Remove(scriptConfig);
                 });
                 UpdateScriptConfig();
             }
         }
     }
     catch (Exception ex)
     {
         DotaViewModel.GameBrowserVm.MainViewModel.ShowError(ex.Message);
         Log.Error(ex, "null");
     }
 }