Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove start steam button and logic #15

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/SteamSpy/Resources/Language/Russian.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<!-- Main Page -->
<system:String x:Key="LaunchGame">Запустить игру</system:String>
<system:String x:Key="LaunchSteamGame">Запустить steam</system:String>
<system:String x:Key="FoundErrors">Есть несколько рекомендации для повышения комфорта Вашей игры!</system:String>
<system:String x:Key="ShowIt">Посмотреть!</system:String>
<system:String x:Key="SteamNotLaunched">Стим не запущен!</system:String>
Expand Down
78 changes: 28 additions & 50 deletions src/SteamSpy/Services/Implementations/LaunchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public class LaunchService : ILaunchService

private static EventWaitHandle threadWaitHandle;

public Task LaunchGameAndWait(String server, String mode, IGlobalNavigationManager navigationManager)
public Task LaunchGameAndWait(String mode, IGlobalNavigationManager navigationManager)
{


_authorizationWindowShow =
false; // флаг, который указывает, что окно авторизации уже было выведено пользователю.
_shouldStopRunSs =
Expand All @@ -51,9 +49,8 @@ public Task LaunchGameAndWait(String server, String mode, IGlobalNavigationManag

if (!CoreContext.LaunchService.TryGetOrChoosePath(out var path))
return Task.CompletedTask;

Logger.Info("Launch game procedure started. Game path: "+ path);


Logger.Info("Launch game procedure started. Game path: " + path);

CoreContext.OpenLogsService.Log($"Launch Game");

Expand All @@ -62,7 +59,7 @@ public Task LaunchGameAndWait(String server, String mode, IGlobalNavigationManag
ProcessManager.KillAllGameProccessesWithoutWindow();
threadWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);

if (!CoreContext.MasterServer.IsConnected && server == "thunderhawk")
if (!CoreContext.MasterServer.IsConnected)
throw new Exception("Server is unavailable");

if (ProcessManager.GameIsRunning())
Expand Down Expand Up @@ -117,58 +114,40 @@ public Task LaunchGameAndWait(String server, String mode, IGlobalNavigationManag
{
try
{
var exeFileName = server == "thunderhawk"
? Path.Combine(Environment.CurrentDirectory, "GameFiles", "Patch1.2", "Soulstorm.exe")
: Path.Combine(PathFinder.GamePath, "Soulstorm.exe");
var exeFileName = Path.Combine(Environment.CurrentDirectory, "GameFiles", "Patch1.2",
"Soulstorm.exe");
var procParams = "-nomovies -forcehighpoly";

if (server == "thunderhawk")
{
CopySchemes(path);
CopySchemes(path);

if (mode == "Classic bug fix")
{
procParams += " -modname JBugfixMod";
}
else
{
procParams += " -modname ThunderHawk";
}

Logger.Info("Start "+ exeFileName +" with params " + procParams);
var ssProc = Process.Start(new ProcessStartInfo(exeFileName, procParams)
{
UseShellExecute = true,
WorkingDirectory = path
});

GameProcess = ssProc;
if (mode == "Classic bug fix")
{
procParams += " -modname JBugfixMod";
}
else
{
procParams += " -modname ThunderHawk";
}

CoreContext.ClientServer.Start();
Logger.Info("Start " + exeFileName + " with params " + procParams);
var ssProc = Process.Start(new ProcessStartInfo(exeFileName, procParams)
{
UseShellExecute = true,
WorkingDirectory = path
});

ssProc.EnableRaisingEvents = true;
GameProcess = ssProc;

Task.Run(() => RemoveFogLoop(tcs.Task, ssProc));
CoreContext.ClientServer.Start();

// to read warning.log from the begining after start game
Task.Delay(10000).ContinueWith(t => { CoreContext.InGameService.DropSsConsoleOffset(); });
ssProc.EnableRaisingEvents = true;

ssProc.Exited += (s, e) => { tcs.TrySetResult(ssProc); };
}
else
{
Process steamGameProc = new Process();
Task.Run(() => RemoveFogLoop(tcs.Task, ssProc));

StartApp();
// to read warning.log from the begining after start game
Task.Delay(10000).ContinueWith(t => { CoreContext.InGameService.DropSsConsoleOffset(); });

void StartApp()
{
steamGameProc.StartInfo.FileName = SteamApiHelper.GetSteamExePath();
steamGameProc.StartInfo.Arguments =
"-applaunch 9450 -modname DXP2 -nomovies -forcehighpoly";
steamGameProc.Start();
}
}
ssProc.Exited += (s, e) => { tcs.TrySetResult(ssProc); };
}
catch (Exception ex)
{
Expand Down Expand Up @@ -203,7 +182,6 @@ void canAuthorizeReceive(bool canAuthorize)

void GetUserNicks(string[] nicks)
{

if (!_authorizationWindowShow)
{
if (nicks.Length == 0)
Expand Down
15 changes: 0 additions & 15 deletions src/SteamSpy/Views/Elements/Element_Main.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,6 @@
Opacity="0.4" />
</Button.Effect>
</Button>

<Button
Margin="10 8 0 0"
Padding="8 8 8 8"
Width="200"
Height="52"
FontSize="15"
framework:WPFBinder.Frame="LaunchSteamGame"
Content="{DynamicResource LaunchSteamGame}"
Style="{DynamicResource LaunchButtonStyle2}">
<Button.Effect>
<DropShadowEffect Color="Black" Direction="270" ShadowDepth="2" BlurRadius="10"
Opacity="0.4" />
</Button.Effect>
</Button>
</StackPanel>


Expand Down
2 changes: 1 addition & 1 deletion src/ThunderHawk.Core/Services/ILaunchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ILaunchService
bool IsGamePreparingToStart { set; get; }
Process GameProcess { get; }

Task LaunchGameAndWait(String server, String mode, IGlobalNavigationManager globalNavigationManager);
Task LaunchGameAndWait(String mode, IGlobalNavigationManager globalNavigationManager);
bool TryGetOrChoosePath(out string path);
void ChangeGamePath();
void ActivateGameWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ protected override void OnBind()

Frame.ActiveModRevision.Text = $"Thunderhawk <b>" + CoreContext.ThunderHawkModManager.ValidModVersion + "</b>";
Frame.LaunchGame.Action = LaunchThunderhawk;
Frame.LaunchSteamGame.Action = LaunchSteam;

// InGamePage
Frame.InGameLabel.Text = "Refresh";
Expand Down Expand Up @@ -95,13 +94,11 @@ void OpenTweaks()
public void LaunchThunderhawk()
{
Frame.LaunchGame.Enabled = false;
Frame.LaunchSteamGame.Enabled = false;
Frame.LaunchGame.Text = "Thunderhawk launched";
Frame.LaunchSteamGame.Text = "Thunderhawk launched";
Frame.NewsVisible = false;
Frame.InGameVisible = true;

CoreContext.LaunchService.LaunchGameAndWait("thunderhawk", Frame.GameModeSelectedValue, Frame.GlobalNavigationManager)
CoreContext.LaunchService.LaunchGameAndWait(Frame.GameModeSelectedValue, Frame.GlobalNavigationManager)
.OnFaultOnUi(ex =>
{
if (!(ex is UnauthorizedAccessException)) // иначе мы просто окно выведем и попросим юзера авторизоавться
Expand All @@ -115,26 +112,10 @@ public void LaunchThunderhawk()
});
}

void LaunchSteam()
{
Frame.LaunchGame.Enabled = false;
Frame.LaunchSteamGame.Enabled = false;
Frame.LaunchGame.Text = "Steam launched";
Frame.LaunchSteamGame.Text = "Steam launched";

//TODO: пофиксить этот костыль нормальным определением запущенного стим СС
Task.Delay(10000).ContinueWith(t => RunOnUIThread(() => { ResetButtons(); }));

CoreContext.LaunchService.LaunchGameAndWait("steam", Frame.GameModeSelectedValue, Frame.GlobalNavigationManager)
.OnFaultOnUi(ex => Frame.UserInteractions.ShowErrorNotification(ex.Message));
}

void ResetButtons()
{
Frame.LaunchGame.Text = "Launch Thunderhawk";
Frame.LaunchSteamGame.Text = "Launch Steam";
Frame.LaunchGame.Enabled = true;
Frame.LaunchSteamGame.Enabled = true;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public class MainPageViewModel : EmbeddedPageViewModel, INotifyPropertyChanged
public ControlFrame LoadingIndicator { get; } = new ControlFrame() { Visible = false };
public ListFrame<NewsItemViewModel> News { get; } = new ListFrame<NewsItemViewModel>();
public ButtonFrame LaunchGame { get; } = new ButtonFrame() { Text = "Launch Thunderhawk" };

public ButtonFrame LaunchSteamGame { get; } = new ButtonFrame() { Text = "Launch Steam" };
public ActionFrame FAQLabel { get; } = new ActionFrame();

public ActionFrame Tweaks { get; } = new ActionFrame();
Expand Down