Skip to content

Commit

Permalink
Launch games with runGame command. Fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
tkashkin committed Oct 22, 2017
1 parent 027386f commit 5ac19f6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 43 deletions.
6 changes: 0 additions & 6 deletions GOGWrapper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GOGWrapper", "GOGWrapper\GO
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9A18280C-D97E-4753-9ED9-690091A7355F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A18280C-D97E-4753-9ED9-690091A7355F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A18280C-D97E-4753-9ED9-690091A7355F}.Debug|x86.ActiveCfg = Debug|x86
{9A18280C-D97E-4753-9ED9-690091A7355F}.Debug|x86.Build.0 = Debug|x86
{9A18280C-D97E-4753-9ED9-690091A7355F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A18280C-D97E-4753-9ED9-690091A7355F}.Release|Any CPU.Build.0 = Release|Any CPU
{9A18280C-D97E-4753-9ED9-690091A7355F}.Release|x86.ActiveCfg = Release|x86
{9A18280C-D97E-4753-9ED9-690091A7355F}.Release|x86.Build.0 = Release|x86
EndGlobalSection
Expand Down
47 changes: 31 additions & 16 deletions GOGWrapper/GOG/GOGGalaxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,10 @@ public static void open(string id)

public static void launch(string id, Action callback = null)
{
GOGGalaxy.open(id);

IntPtr hwnd = WinAPI.FindWindow("GalaxyClientClass", null);

bool windowExists = WinAPI.IsWindow(hwnd);

Thread.Sleep(500);

if (!windowExists)
{
hwnd = WinAPI.WaitForWindow("GalaxyClientClass", null);
Thread.Sleep(5000);
}

WinAPI.SetForegroundWindow(hwnd);
WinAPI.Click(hwnd, new System.Drawing.Point(_x, _y));
// GOGGalaxy.launchWinapi(id); // old hacky way

Process.Start(GOGRegistry.ClientExecutable, $@"/gameid {id} /command runGame");
GOGGalaxy.waitForStartup();

GOGGame game = GOGRegistry.Game(id);

Expand Down Expand Up @@ -84,6 +72,33 @@ public static void launch(string id, Action callback = null)
callback?.Invoke();
}

private static void launchWinapi(string id)
{
GOGGalaxy.open(id);

IntPtr hwnd = GOGGalaxy.waitForStartup();

WinAPI.SetForegroundWindow(hwnd);
WinAPI.Click(hwnd, new System.Drawing.Point(_x, _y));
}

private static IntPtr waitForStartup()
{
IntPtr hwnd = WinAPI.FindWindow("GalaxyClientClass", null);

bool windowExists = WinAPI.IsWindow(hwnd);

Thread.Sleep(500);

if (!windowExists)
{
hwnd = WinAPI.WaitForWindow("GalaxyClientClass", null);
Thread.Sleep(5000);
}

return hwnd;
}

private static string normalize(string path)
{
return Path.GetFullPath(new Uri(path).LocalPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
Expand Down
21 changes: 0 additions & 21 deletions GOGWrapper/GOGWrapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
Expand Down

2 comments on commit 5ac19f6

@lbacud
Copy link

@lbacud lbacud commented on 5ac19f6 Oct 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to release a binary of this?

@tkashkin
Copy link
Owner Author

@tkashkin tkashkin commented on 5ac19f6 Oct 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.