2016-08-28 05:57:46 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2018-01-02 03:59:14 +13:00
|
|
|
|
Copyright (c) 2007-2018 ShareX Team
|
2016-08-28 05:57:46 +12:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-03-01 11:52:11 +13:00
|
|
|
|
using System.Collections.Generic;
|
2016-08-28 05:57:46 +12:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2017-05-06 02:15:49 +12:00
|
|
|
|
using System.Linq;
|
2018-03-01 11:52:11 +13:00
|
|
|
|
using System.Net;
|
2016-08-28 05:57:46 +12:00
|
|
|
|
|
|
|
|
|
namespace ShareX.Setup
|
|
|
|
|
{
|
2018-03-03 10:17:01 +13:00
|
|
|
|
internal class SetupHelpers
|
2016-08-28 05:57:46 +12:00
|
|
|
|
{
|
|
|
|
|
public static string DownloadFile(string url)
|
|
|
|
|
{
|
2016-08-28 06:35:13 +12:00
|
|
|
|
Console.WriteLine("Downloading: " + url);
|
|
|
|
|
|
2017-03-12 09:54:42 +13:00
|
|
|
|
using (WebClient wc = new WebClient())
|
2016-08-28 05:57:46 +12:00
|
|
|
|
{
|
|
|
|
|
string filename = Path.GetFileName(url);
|
2017-03-12 09:54:42 +13:00
|
|
|
|
wc.DownloadFile(url, filename);
|
2016-08-28 05:57:46 +12:00
|
|
|
|
return filename;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-28 06:35:13 +12:00
|
|
|
|
public static void CopyFile(string path, string toFolder)
|
|
|
|
|
{
|
|
|
|
|
CopyFiles(new string[] { path }, toFolder);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-06 02:15:49 +12:00
|
|
|
|
public static void CopyFiles(IEnumerable<string> files, string toFolder)
|
2016-08-28 05:57:46 +12:00
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(toFolder))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(toFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (string filepath in files)
|
|
|
|
|
{
|
|
|
|
|
string filename = Path.GetFileName(filepath);
|
|
|
|
|
string dest = Path.Combine(toFolder, filename);
|
|
|
|
|
File.Copy(filepath, dest);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-06 02:15:49 +12:00
|
|
|
|
public static void CopyFiles(string directory, string searchPattern, string toFolder, string[] ignoreFiles = null)
|
2016-08-28 05:57:46 +12:00
|
|
|
|
{
|
2017-05-06 02:15:49 +12:00
|
|
|
|
string[] files = Directory.GetFiles(directory, searchPattern);
|
|
|
|
|
|
|
|
|
|
if (ignoreFiles != null)
|
|
|
|
|
{
|
|
|
|
|
List<string> newFiles = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach (string file in files)
|
|
|
|
|
{
|
|
|
|
|
string filename = Path.GetFileName(file);
|
|
|
|
|
|
|
|
|
|
if (ignoreFiles.All(x => !filename.Equals(x, StringComparison.InvariantCultureIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
newFiles.Add(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
files = newFiles.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CopyFiles(files, toFolder);
|
2016-08-28 05:57:46 +12:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-18 22:28:28 +13:00
|
|
|
|
private static void ProcessStart(string filePath, string arguments)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Process starting: {filePath} {arguments}");
|
2016-08-28 06:35:13 +12:00
|
|
|
|
|
2016-08-28 05:57:46 +12:00
|
|
|
|
ProcessStartInfo startInfo = new ProcessStartInfo()
|
|
|
|
|
{
|
2017-12-18 22:28:28 +13:00
|
|
|
|
FileName = filePath,
|
|
|
|
|
Arguments = arguments,
|
2017-12-18 22:04:22 +13:00
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
CreateNoWindow = true
|
2016-08-28 05:57:46 +12:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Process.Start(startInfo).WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool CheckArguments(string[] args, string check)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(check))
|
|
|
|
|
{
|
|
|
|
|
foreach (string arg in args)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(arg) && arg.Equals(check, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|