Fix Wox restart

1. refactoring restart
2. delte some windows forms methods
3. using string inteperlation and delete hard coeded new line char

should fix #322
This commit is contained in:
bao-qian
2015-11-26 02:04:44 +00:00
parent f0765ba743
commit 6023f415a4
9 changed files with 71 additions and 58 deletions

View File

@@ -1,10 +1,10 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Zip;
using Newtonsoft.Json;
using Wox.Plugin;
using System.Windows;
namespace Wox.Core.Plugin
{
@@ -47,22 +47,24 @@ namespace Wox.Core.Plugin
.Replace("*", "_")
.Replace("|", "_")
+ "-" + Guid.NewGuid();
string newPluginPath = Path.Combine(pluginFolerPath,newPluginName);
string content = string.Format(
"Do you want to install following plugin?\r\n\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}",
plugin.Name, plugin.Version, plugin.Author);
string newPluginPath = Path.Combine(pluginFolerPath, newPluginName);
string content = $"Do you want to install following plugin?{Environment.NewLine}{Environment.NewLine}" +
$"Name: {plugin.Name}{Environment.NewLine}" +
$"Version: {plugin.Version}{Environment.NewLine}" +
$"Author: {plugin.Author}";
PluginPair existingPlugin = PluginManager.GetPluginForId(plugin.ID);
if (existingPlugin != null)
{
content = string.Format(
"Do you want to update following plugin?\r\n\r\nName: {0}\r\nOld Version: {1}\r\nNew Version: {2}\r\nAuthor: {3}",
plugin.Name, existingPlugin.Metadata.Version, plugin.Version, plugin.Author);
content = $"Do you want to update following plugin?{Environment.NewLine}{Environment.NewLine}" +
$"Name: {plugin.Name}{Environment.NewLine}" +
$"Old Version: {existingPlugin.Metadata.Version}" +
$"{Environment.NewLine}New Version: {plugin.Version}" +
$"{Environment.NewLine}Author: {plugin.Author}";
}
DialogResult result = System.Windows.Forms.MessageBox.Show(content, "Install plugin", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
var result = MessageBox.Show(content, "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory))
{
@@ -81,17 +83,11 @@ namespace Wox.Core.Plugin
//{
// Plugins.Init();
//}
if (MessageBox.Show("You have installed plugin " + plugin.Name + " successfully.\r\n Restart Wox to take effect?", "Install plugin",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine}" +
" Restart Wox to take effect?",
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
ProcessStartInfo Info = new ProcessStartInfo();
Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" +
System.Windows.Forms.Application.ExecutablePath + "\"";
Info.WindowStyle = ProcessWindowStyle.Hidden;
Info.CreateNoWindow = true;
Info.FileName = "cmd.exe";
Process.Start(Info);
PluginManager.API.CloseApp();
PluginManager.API.RestarApp();
}
}
}
@@ -114,7 +110,7 @@ namespace Wox.Core.Plugin
}
catch (System.Exception)
{
string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
string error = $"Parse plugin config {configPath} failed: json format is not valid";
#if (DEBUG)
{
throw new System.Exception(error);
@@ -126,8 +122,7 @@ namespace Wox.Core.Plugin
if (!AllowedLanguage.IsAllowed(metadata.Language))
{
string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath,
metadata.Language);
string error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
#if (DEBUG)
{
throw new System.Exception(error);
@@ -137,8 +132,7 @@ namespace Wox.Core.Plugin
}
if (!File.Exists(metadata.ExecuteFilePath))
{
string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath,
metadata.ExecuteFilePath);
string error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
#if (DEBUG)
{
throw new System.Exception(error);