Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Fixed game service launcher conn error
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Apr 27, 2023
1 parent 61d8a7d commit b183607
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 31 deletions.
24 changes: 14 additions & 10 deletions src/GenshinSwitch.WindowsService/CommandRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace GenshinSwitch.WindowsService;

Expand Down Expand Up @@ -64,18 +65,21 @@ internal static class CommandRunner
}
else if ((int)obj.Command == (int)MainServiceCommmand.LaunchProcess)
{
using Process p = Process.Start(new ProcessStartInfo()
_ = Task.Run(() =>
{
UseShellExecute = DynamicExtension.IsNullOrSelf(obj, "UseShellExecute", true),
FileName = obj.FileName,
Arguments = DynamicExtension.IsNullOrSelf(obj, "Arguments", string.Empty),
WorkingDirectory = DynamicExtension.IsNullOrSelf(obj, "WorkingDirectory", string.Empty),
Verb = DynamicExtension.IsNullOrSelf(obj, "Verb", string.Empty),
using Process p = Process.Start(new ProcessStartInfo()
{
UseShellExecute = DynamicExtension.IsNullOrSelf(obj, "UseShellExecute", true),
FileName = obj.FileName,
Arguments = DynamicExtension.IsNullOrSelf(obj, "Arguments", string.Empty),
WorkingDirectory = DynamicExtension.IsNullOrSelf(obj, "WorkingDirectory", string.Empty),
Verb = DynamicExtension.IsNullOrSelf(obj, "Verb", string.Empty),
});
if (DynamicExtension.IsNullOrSelf(obj, "WaitForExit", false))
{
p.WaitForExit();
}
});
if (obj.IsNullOrSelf("WaitForExit", false))
{
p.WaitForExit();
}
}
else if ((int)obj.Command == (int)MainServiceCommmand.Kill)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<LangVersion>11.0</LangVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>Sapphire.ico</ApplicationIcon>
<AssemblyVersion>1.0.2</AssemblyVersion>
<FileVersion>1.0.2</FileVersion>
<Version>$(VersionPrefix)1.0.2</Version>
<AssemblyVersion>1.0.3</AssemblyVersion>
<FileVersion>1.0.3</FileVersion>
<Version>$(VersionPrefix)1.0.3</Version>
<Authors>GenshinMatrix</Authors>
<Company>GenshinMatrix</Company>
<PublisherName>GenshinMatrix</PublisherName>
Expand Down
27 changes: 14 additions & 13 deletions src/GenshinSwitch.WindowsService/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,22 @@ protected override void OnStart(string[] args)
{
thread = new Thread(() =>
{
try
{
isRunning = true;
isRunning = true;

PipeSecurity ps = new();
ps.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null!), PipeAccessRights.ReadWrite, AccessControlType.Allow));
ps.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, AccessControlType.Allow));
PipeSecurity ps = new();
ps.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null!), PipeAccessRights.ReadWrite, AccessControlType.Allow));
ps.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, AccessControlType.Allow));

while (isRunning)
while (isRunning)
{
try
{
using NamedPipeServerStream pipeServer = new("GenshinSwitch.WindowsService", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 99999, 99999, ps);
pipeServer.WaitForConnection();
using StreamReader reader = new(pipeServer);


Debug.WriteLine("GenshinSwitch.WindowsService REACHED");

try
{
string? cmd = reader.ReadLine();
Expand All @@ -102,18 +104,17 @@ protected override void OnStart(string[] args)
writer.WriteLine(ret);
writer.Flush();
Debug.WriteLine("Send message: " + ret);
Thread.Sleep(999);
}
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
}
catch (Exception e)
{
Debug.WriteLine(e);
catch (Exception e)
{
Debug.WriteLine(e);
}
}
});
thread.Start();
Expand Down
6 changes: 3 additions & 3 deletions src/GenshinSwitch/GenshinSwitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<ApplicationIcon>Assets/Logos/Favicon.ico</ApplicationIcon>
<Platforms>x64</Platforms>
<PlatformTarget>x64</PlatformTarget>
<AssemblyVersion>2.1.0</AssemblyVersion>
<FileVersion>2.1.0</FileVersion>
<Version>$(VersionPrefix)2.1.0</Version>
<AssemblyVersion>2.1.1</AssemblyVersion>
<FileVersion>2.1.1</FileVersion>
<Version>$(VersionPrefix)2.1.1</Version>
<Authors>GenshinMatrix</Authors>
<Company>GenshinMatrix</Company>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
Expand Down
2 changes: 1 addition & 1 deletion src/GenshinSwitch/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Identity
Name="E0F0B14C-9CA5-4B60-8B6E-0DC219EBB4A7"
Publisher="CN=ema"
Version="2.1.0.0" />
Version="2.1.1.0" />

<Properties>
<DisplayName>GenshinSwitch</DisplayName>
Expand Down
7 changes: 6 additions & 1 deletion src/GenshinSwitch/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,19 @@ await AddOrUpdateContactAsync(new ContactMessage()
}
}

private DateTime doubleClickLimit = DateTime.MinValue;
public void OnContactListViewItemClick(object sender, ItemClickEventArgs e)
{
if (ListViewHelper.TryRaiseItemDoubleClick(sender, e))
{
if (Settings.DoubleClickBehavior == 0
|| Settings.DoubleClickBehavior == 1)
{
LaunchGameAsync((Contact)e.ClickedItem).Forget();
if (DateTime.Now.Subtract(doubleClickLimit).TotalSeconds >= 2d)
{
doubleClickLimit = DateTime.Now;
LaunchGameAsync((Contact)e.ClickedItem).Forget();
}
}
}
}
Expand Down

0 comments on commit b183607

Please sign in to comment.