mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Merge branch 'master' of https://github.com/EmilyLove26/ShareX
This commit is contained in:
commit
e12e05ae40
1 changed files with 35 additions and 22 deletions
|
@ -42,20 +42,17 @@ public static class Launcher
|
|||
private static string UpdateFolderPath = Helpers.GetAbsolutePath("Updates");
|
||||
private static string UpdateExecutablePath = Path.Combine(UpdateFolderPath, "ShareX.exe");
|
||||
|
||||
private static bool IsFirstTimeRunning, IsStartupRun, ShowInApp;
|
||||
private static bool IsFirstTimeRunning, IsStartupRun, ShowInApp, IsSteamInit;
|
||||
private static Stopwatch SteamInitStopwatch;
|
||||
|
||||
public static void Run(string[] args)
|
||||
{
|
||||
Stopwatch startTimer = Stopwatch.StartNew();
|
||||
|
||||
if (Helpers.IsCommandExist(args, "-uninstall"))
|
||||
{
|
||||
UninstallShareX();
|
||||
return;
|
||||
}
|
||||
|
||||
bool isSteamInit = false;
|
||||
|
||||
IsStartupRun = Helpers.IsCommandExist(args, "-silent");
|
||||
|
||||
#if DEBUG
|
||||
|
@ -66,7 +63,7 @@ public static void Run(string[] args)
|
|||
|
||||
if (!IsShareXRunning())
|
||||
{
|
||||
// If running on startup and need to show "In-app" then wait until Steam is open
|
||||
// If running on startup and need to show "In-app" then wait for Steam to run.
|
||||
if (IsStartupRun && ShowInApp)
|
||||
{
|
||||
for (int i = 0; i < 30 && !SteamAPI.IsSteamRunning(); i++)
|
||||
|
@ -77,15 +74,27 @@ public static void Run(string[] args)
|
|||
|
||||
if (SteamAPI.IsSteamRunning())
|
||||
{
|
||||
isSteamInit = SteamAPI.Init();
|
||||
// Even "IsSteamRunning" is true still Steam API init can fail, therefore need to give more time for Steam to launch.
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
IsSteamInit = SteamAPI.Init();
|
||||
|
||||
if (IsSteamInit)
|
||||
{
|
||||
SteamInitStopwatch = Stopwatch.StartNew();
|
||||
break;
|
||||
}
|
||||
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsUpdateRequired())
|
||||
{
|
||||
DoUpdate();
|
||||
UpdateShareX();
|
||||
}
|
||||
|
||||
if (isSteamInit)
|
||||
if (IsSteamInit)
|
||||
{
|
||||
SteamAPI.Shutdown();
|
||||
}
|
||||
|
@ -97,23 +106,27 @@ public static void Run(string[] args)
|
|||
|
||||
if (IsFirstTimeRunning)
|
||||
{
|
||||
// Show first time config window
|
||||
// Show first time config window.
|
||||
arguments = "-SteamConfig";
|
||||
}
|
||||
else if (IsStartupRun)
|
||||
{
|
||||
// Don't show ShareX main window
|
||||
// Don't show ShareX main window.
|
||||
arguments = "-silent";
|
||||
}
|
||||
|
||||
RunShareX(arguments);
|
||||
|
||||
if (isSteamInit)
|
||||
if (IsSteamInit)
|
||||
{
|
||||
// Reason for this workaround because Steam only allows writing review if you played game at least 5 minutes
|
||||
// So launcher will stay on for 10 seconds and eventually users can reach 5 minutes that way (It will require 30 times opening)
|
||||
// Otherwise nobody can write review
|
||||
int waitTime = 10000 - (int)startTimer.ElapsedMilliseconds;
|
||||
// Reason for this workaround is because Steam only allows writing review if user is played the game at least 5 minutes.
|
||||
// For this reason ShareX launcher will stay on for at least 10 seconds to let users eventually reach 5 minutes play time.
|
||||
int waitTime = 10000;
|
||||
|
||||
if (SteamInitStopwatch != null)
|
||||
{
|
||||
waitTime -= (int)SteamInitStopwatch.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
if (waitTime > 0)
|
||||
{
|
||||
|
@ -139,7 +152,7 @@ private static string GetContentFolderPath()
|
|||
|
||||
private static bool IsShareXRunning()
|
||||
{
|
||||
// Check ShareX mutex
|
||||
// Check ShareX mutex.
|
||||
return Helpers.IsRunning("82E6AC09-0FEF-4390-AD9F-0DD3F5561EFC");
|
||||
}
|
||||
|
||||
|
@ -180,7 +193,7 @@ private static bool IsUpdateRequired()
|
|||
return false;
|
||||
}
|
||||
|
||||
private static void DoUpdate()
|
||||
private static void UpdateShareX()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -189,7 +202,7 @@ private static void DoUpdate()
|
|||
Directory.CreateDirectory(ContentFolderPath);
|
||||
}
|
||||
|
||||
// In case updating terminate middle of it, in next Launcher start it can repair
|
||||
// In case updating process terminate middle of it, allow launcher to repair ShareX.
|
||||
Helpers.CreateEmptyFile(UpdatingTempFilePath);
|
||||
Helpers.CopyAll(UpdateFolderPath, ContentFolderPath);
|
||||
File.Delete(UpdatingTempFilePath);
|
||||
|
@ -228,10 +241,10 @@ private static void RunShareX(string arguments = "")
|
|||
{
|
||||
try
|
||||
{
|
||||
// Workaround for don't show "In-app"
|
||||
// Workaround to don't show "In-app".
|
||||
uint result = Helpers.WinExec($"\"{ContentExecutablePath}\" {arguments}", 5);
|
||||
|
||||
// If the function succeeds, the return value is greater than 31
|
||||
// If the function succeeds, the return value is greater than 31.
|
||||
if (result > 31)
|
||||
{
|
||||
return;
|
||||
|
@ -241,7 +254,7 @@ private static void RunShareX(string arguments = "")
|
|||
{
|
||||
}
|
||||
|
||||
// Workaround 2
|
||||
// Workaround 2.
|
||||
string path = Path.Combine(Environment.SystemDirectory, "cmd.exe");
|
||||
|
||||
if (!File.Exists(path))
|
||||
|
|
Loading…
Reference in a new issue