mirror of
https://github.com/ShareX/ShareX.git
synced 2024-08-20 12:41:29 +12:00
236 lines
No EOL
9.5 KiB
C#
236 lines
No EOL
9.5 KiB
C#
#region License Information (GPL v3)
|
|
|
|
/*
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
|
Copyright (c) 2007-2016 ShareX Team
|
|
|
|
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;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace ShareX.Setup
|
|
{
|
|
internal class Program
|
|
{
|
|
private enum SetupType
|
|
{
|
|
Stable, // Build setup & create portable zip file
|
|
BuildSetup, // Build setup
|
|
CreatePortable, // Create portable zip file
|
|
PortableApps, // Create PortableApps folder
|
|
Beta, // Build setup & upload it using "Debug/ShareX.exe"
|
|
Steam // Create Steam folder
|
|
}
|
|
|
|
private static readonly SetupType Setup = SetupType.Stable;
|
|
|
|
private static readonly string parentDir = @"..\..\..\";
|
|
private static readonly string binDir = Path.Combine(parentDir, "ShareX", "bin");
|
|
private static readonly string releaseDir = Path.Combine(binDir, "Release");
|
|
private static readonly string debugDir = Path.Combine(binDir, "Debug");
|
|
private static readonly string steamDir = Path.Combine(binDir, "Steam");
|
|
private static readonly string debugPath = Path.Combine(debugDir, "ShareX.exe");
|
|
private static readonly string innoSetupDir = Path.Combine(parentDir, @"ShareX.Setup\InnoSetup");
|
|
private static readonly string outputDir = Path.Combine(innoSetupDir, "Output");
|
|
private static readonly string portableDir = Path.Combine(outputDir, "ShareX-portable");
|
|
private static readonly string steamOutputDir = Path.Combine(outputDir, "ShareX");
|
|
private static readonly string portableAppsDir = Path.Combine(parentDir, @"..\PortableApps\ShareXPortable\App\ShareX");
|
|
private static readonly string steamLauncherDir = Path.Combine(parentDir, @"..\ShareX_Steam\ShareX_Steam\bin\Release");
|
|
private static readonly string steamUpdatesDir = Path.Combine(steamOutputDir, "Updates");
|
|
private static readonly string chromeReleaseDir = Path.Combine(parentDir, @"..\ShareX_Chrome\ShareX_Chrome\bin\Release");
|
|
private static readonly string innoSetupCompilerPath = @"C:\Program Files (x86)\Inno Setup 5\ISCC.exe";
|
|
private static readonly string innoSetupScriptPath = Path.Combine(innoSetupDir, "ShareX-setup.iss");
|
|
private static readonly string zipPath = @"C:\Program Files\7-Zip\7z.exe";
|
|
|
|
private static string ReleaseDirectory => Setup == SetupType.Steam ? steamDir : releaseDir;
|
|
|
|
private static void Main(string[] args)
|
|
{
|
|
Console.WriteLine("Setup type: " + Setup);
|
|
|
|
switch (Setup)
|
|
{
|
|
case SetupType.Stable:
|
|
CompileSetup();
|
|
CreatePortable(portableDir);
|
|
OpenOutputDirectory();
|
|
break;
|
|
case SetupType.BuildSetup:
|
|
CompileSetup();
|
|
OpenOutputDirectory();
|
|
break;
|
|
case SetupType.CreatePortable:
|
|
CreatePortable(portableDir);
|
|
OpenOutputDirectory();
|
|
break;
|
|
case SetupType.PortableApps:
|
|
CreatePortable(portableAppsDir);
|
|
OpenOutputDirectory();
|
|
break;
|
|
case SetupType.Beta:
|
|
CompileSetup();
|
|
UploadLatestFile();
|
|
break;
|
|
case SetupType.Steam:
|
|
CreateSteamFolder();
|
|
OpenOutputDirectory();
|
|
break;
|
|
}
|
|
|
|
Console.WriteLine("Done.");
|
|
}
|
|
|
|
private static void OpenOutputDirectory()
|
|
{
|
|
Process.Start("explorer.exe", outputDir);
|
|
}
|
|
|
|
private static void UploadLatestFile()
|
|
{
|
|
FileInfo fileInfo = new DirectoryInfo(outputDir).GetFiles("*.exe").OrderByDescending(f => f.LastWriteTime).FirstOrDefault();
|
|
if (fileInfo != null)
|
|
{
|
|
Console.WriteLine("Uploading setup file...");
|
|
Process.Start(debugPath, fileInfo.FullName);
|
|
}
|
|
}
|
|
|
|
private static void CompileSetup()
|
|
{
|
|
Console.WriteLine("Compiling setup...");
|
|
Process.Start(innoSetupCompilerPath, string.Format("\"{0}\"", innoSetupScriptPath)).WaitForExit();
|
|
Console.WriteLine("Setup file created.");
|
|
}
|
|
|
|
private static void CreateSteamFolder()
|
|
{
|
|
if (Directory.Exists(steamOutputDir))
|
|
{
|
|
Directory.Delete(steamOutputDir, true);
|
|
}
|
|
|
|
Directory.CreateDirectory(steamOutputDir);
|
|
|
|
CopyFile(Path.Combine(steamLauncherDir, "ShareX_Launcher.exe"), steamOutputDir);
|
|
CopyFile(Path.Combine(steamLauncherDir, "steam_appid.txt"), steamOutputDir);
|
|
CopyFile(Path.Combine(steamLauncherDir, "installscript.vdf"), steamOutputDir);
|
|
CopyFiles(steamLauncherDir, "*.dll", steamOutputDir);
|
|
|
|
CreatePortable(steamUpdatesDir);
|
|
}
|
|
|
|
private static void CreatePortable(string destination)
|
|
{
|
|
Console.WriteLine("Creating portable...");
|
|
|
|
if (Directory.Exists(destination))
|
|
{
|
|
Directory.Delete(destination, true);
|
|
}
|
|
|
|
Directory.CreateDirectory(destination);
|
|
|
|
CopyFile(Path.Combine(ReleaseDirectory, "ShareX.exe"), destination);
|
|
CopyFile(Path.Combine(ReleaseDirectory, "ShareX.exe.config"), destination);
|
|
CopyFiles(ReleaseDirectory, "*.dll", destination);
|
|
CopyFiles(Path.Combine(parentDir, "Licenses"), "*.txt", Path.Combine(destination, "Licenses"));
|
|
CopyFile(Path.Combine(outputDir, "Recorder-devices-setup.exe"), destination);
|
|
CopyFile(Path.Combine(chromeReleaseDir, "ShareX_Chrome.exe"), destination);
|
|
|
|
string[] languages = new string[] { "de", "es", "fr", "hu", "ko-KR", "nl-NL", "pt-BR", "ru", "tr", "vi-VN", "zh-CN" };
|
|
|
|
foreach (string language in languages)
|
|
{
|
|
CopyFiles(Path.Combine(ReleaseDirectory, language), "*.resources.dll", Path.Combine(destination, "Languages", language));
|
|
}
|
|
|
|
if (Setup == SetupType.Steam)
|
|
{
|
|
// These git ignored
|
|
CopyFile(Path.Combine(parentDir, "Lib", "ffmpeg.exe"), destination);
|
|
CopyFile(Path.Combine(parentDir, "Lib", "ffmpeg-x64.exe"), destination);
|
|
}
|
|
else if (Setup == SetupType.PortableApps)
|
|
{
|
|
File.Create(Path.Combine(destination, "PortableApps")).Dispose();
|
|
}
|
|
else
|
|
{
|
|
File.Create(Path.Combine(destination, "Portable")).Dispose();
|
|
|
|
//FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(releaseDir, "ShareX.exe"));
|
|
//string zipFilename = string.Format("ShareX-{0}.{1}.{2}-portable.zip", versionInfo.ProductMajorPart, versionInfo.ProductMinorPart, versionInfo.ProductBuildPart);
|
|
string zipPath = Path.Combine(outputDir, "ShareX-portable.zip");
|
|
|
|
if (File.Exists(zipPath))
|
|
{
|
|
File.Delete(zipPath);
|
|
}
|
|
|
|
Zip(destination + "\\*", zipPath);
|
|
|
|
if (Directory.Exists(destination))
|
|
{
|
|
Directory.Delete(destination, true);
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("Portable created.");
|
|
}
|
|
|
|
private static void CopyFiles(string[] files, string toFolder)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
private static void CopyFile(string path, string toFolder)
|
|
{
|
|
CopyFiles(new string[] { path }, toFolder);
|
|
}
|
|
|
|
private static void CopyFiles(string directory, string searchPattern, string toFolder)
|
|
{
|
|
CopyFiles(Directory.GetFiles(directory, searchPattern), toFolder);
|
|
}
|
|
|
|
private static void Zip(string source, string target)
|
|
{
|
|
ProcessStartInfo p = new ProcessStartInfo();
|
|
p.FileName = zipPath;
|
|
p.Arguments = string.Format("a -tzip \"{0}\" \"{1}\" -r -mx=9", target, source);
|
|
p.WindowStyle = ProcessWindowStyle.Hidden;
|
|
Process process = Process.Start(p);
|
|
process.WaitForExit();
|
|
}
|
|
}
|
|
} |