Skip to content

Commit c86fdc3

Browse files
committed
2.12.8.1
1 parent 8c3896d commit c86fdc3

36 files changed

Lines changed: 275 additions & 255 deletions

Plain Craft Launcher 2/Application.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@
368368
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
369369
<Setter Property="FontSize" Value="13" />
370370
<Setter Property="MaxDropDownHeight" Value="320" />
371-
<Setter Property="Cursor" Value="Hand" />
372371
<Setter Property="Template">
373372
<Setter.Value>
374373
<ControlTemplate TargetType="ComboBox">

Plain Craft Launcher 2/Application.xaml.vb

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -91,37 +91,8 @@ RetryCacheCheck:
9191
End Try
9292
DirectoryUtils.Create(PathTemp & "Cache\")
9393
DirectoryUtils.Create(PathAppdata)
94-
95-
#If DEBUG Then
96-
Dim FileLockPath = Path.Combine(PathAppdata.TrimEnd("\"), "PCL.dev.Lock")
97-
#Else
98-
Dim FileLockPath = Path.Combine(PathAppdata.TrimEnd("\"), "PCL.Lock")
99-
#End If
100-
10194
'要求单例
102-
If BuildType <> BuildTypes.Debug Then
103-
If Not GetProgramLock(FileLockPath) Then
104-
Dim IsLocked = False
105-
Dim ShouldWaitForExit As Boolean = e.Args.Length > 0 AndAlso e.Args(0) = "--wait" '要求等待已有的 PCL 退出
106-
If Not ShouldWaitForExit Then
107-
DropToTopByLock(FileLockPath)
108-
Beep()
109-
Environment.Exit(ProcessReturnValues.Cancel)
110-
End If
111-
For i = 0 To 10
112-
If GetProgramLock(FileLockPath) Then
113-
IsLocked = True
114-
Exit For
115-
End If
116-
Thread.Sleep(500)
117-
Next
118-
If Not IsLocked Then
119-
DropToTopByLock(FileLockPath)
120-
Beep()
121-
Environment.Exit(ProcessReturnValues.Cancel)
122-
End If
123-
End If
124-
End If
95+
WaitingMutex(e)
12596
'设置 ToolTipService 默认值
12697
ToolTipService.InitialShowDelayProperty.OverrideMetadata(GetType(DependencyObject), New FrameworkPropertyMetadata(300))
12798
ToolTipService.BetweenShowDelayProperty.OverrideMetadata(GetType(DependencyObject), New FrameworkPropertyMetadata(400))
@@ -173,38 +144,37 @@ RetryCacheCheck:
173144
FormMain.EndProgramForce(ProcessReturnValues.Exception)
174145
End Try
175146
End Sub
176-
177-
Private Shared KernelLock As Mutex
178-
179147
''' <summary>
180-
''' 尝试获取单例锁
148+
''' 要求程序以单例运行。
149+
''' 如果已在运行,则将其窗口拖出来并播放提示音,然后结束当前进程。
181150
''' </summary>
182-
''' <param name="LockPath">文件锁位置</param>
183-
''' <returns>一个值用于指示是否获得文件锁</returns>
184-
Private Function GetProgramLock(LockPath As String) As Boolean
151+
Private Shared Sub WaitingMutex(e As StartupEventArgs)
152+
If BuildType = BuildTypes.Debug Then Return
185153
Try
186-
Dim IsLocked = False
187-
KernelLock = New Mutex(True, "Local\Plain Craft Launcher", IsLocked)
188-
If Not IsLocked Then Return False
189-
Logger.Info("获取单例锁成功")
190-
File.WriteAllText(LockPath, Process.GetCurrentProcess().Id.ToString())
191-
Return IsLocked
154+
Dim MutexCreatedNew As Boolean
155+
PclMutex = New Mutex(True, "PCL_SingletonMutex", MutexCreatedNew)
156+
If MutexCreatedNew Then Return
157+
Logger.Warn("已有一个 PCL 实例正在运行")
158+
'等待已有的 PCL 退出
159+
If e.Args.Length > 0 AndAlso e.Args(0) = "--wait" Then
160+
Try
161+
If PclMutex.WaitOne(10000) Then Return '等待至多 10 秒
162+
Catch Ignored As AbandonedMutexException
163+
Return '已有实例异常退出,继续启动
164+
End Try
165+
End If
166+
'将已有的 PCL 窗口拖出来
167+
Dim WindowHwnd As IntPtr = FindWindow(Nothing, "Plain Craft Launcher ")
168+
If WindowHwnd = IntPtr.Zero Then WindowHwnd = FindWindow(Nothing, "Plain Craft Launcher 2 ")
169+
If WindowHwnd <> IntPtr.Zero Then ShowWindowToTop(WindowHwnd)
170+
'播放提示音并退出
171+
Beep()
172+
Environment.[Exit](ProcessReturnValues.Cancel)
192173
Catch ex As Exception
193-
174+
Logger.Warn(ex, "单例检查失败")
194175
End Try
195-
196-
Return False
197-
End Function
198-
199-
''' <summary>
200-
''' 从文件锁中尝试拖出进程
201-
''' </summary>
202-
Public Sub DropToTopByLock(LockPath As String)
203-
Dim Pid As Integer
204-
If Not Integer.TryParse(File.ReadAllText(LockPath), Pid) Then Return
205-
Dim Handle = Process.GetProcessById(Pid)?.MainWindowHandle
206-
If Handle <> Intptr.Zero Then ShowWindowToTop(Handle)
207176
End Sub
177+
Private Shared PclMutex As Mutex
208178

209179
'结束
210180
Private Sub Application_SessionEnding(sender As Object, e As SessionEndingCancelEventArgs) Handles Me.SessionEnding

Plain Craft Launcher 2/Controls/MyButton.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
FocusVisualStyle="{x:Null}" x:Name="PanBack"
5-
Focusable="True" UseLayoutRounding="False" SnapsToDevicePixels="False" Background="{StaticResource ColorBrushSemiTransparent}" Cursor="Hand">
5+
Focusable="True" UseLayoutRounding="False" SnapsToDevicePixels="False" Background="{StaticResource ColorBrushSemiTransparent}">
66
<Border CornerRadius="3" x:Name="PanFore" BorderThickness="1" BorderBrush="{DynamicResource ColorBrush1}" RenderTransformOrigin="0.5,0.5" Background="{StaticResource ColorBrushHalfWhite}">
77
<Border.RenderTransform>
88
<ScaleTransform />

Plain Craft Launcher 2/Controls/MyCheckBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="MyCheckBox"
55
FocusVisualStyle="{x:Null}"
6-
MinWidth="20" x:Name="PanBack" UseLayoutRounding="False" SnapsToDevicePixels="False" MinHeight="20" Background="{StaticResource ColorBrushSemiTransparent}" Focusable="True" d:DesignWidth="126.4" d:DesignHeight="44.8" Cursor="Hand">
6+
MinWidth="20" x:Name="PanBack" UseLayoutRounding="False" SnapsToDevicePixels="False" MinHeight="20" Background="{StaticResource ColorBrushSemiTransparent}" Focusable="True" d:DesignWidth="126.4" d:DesignHeight="44.8">
77
<TextBlock IsHitTestVisible="False" FontSize="13" x:FieldModifier="Public" x:Name="LabText" Padding="0" Margin="26,0,0,0" Foreground="{DynamicResource ColorBrush1}" HorizontalAlignment="Left" VerticalAlignment="Center" />
88
<Border IsHitTestVisible="False" x:Name="ShapeBorder" BorderThickness="1.1" HorizontalAlignment="Left" VerticalAlignment="Center" Width="18" Height="18" BorderBrush="{DynamicResource ColorBrush1}" CornerRadius="3" Margin="1,0,0,0" Background="{StaticResource ColorBrushHalfWhite}" />
99
<Path IsHitTestVisible="False" x:Name="ShapeCheck" HorizontalAlignment="Left" VerticalAlignment="Center" Fill="{Binding BorderBrush, ElementName=ShapeBorder}" Width="12" Height="12" Margin="4,0,0,0" Data="M0,6L1.5,4.5 4.5,7.5 10.5,1.5 12,3 4.5,10.5 0,6z">

Plain Craft Launcher 2/Controls/MyExtraButton.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="PanBack" mc:Ignorable="d" x:Class="MyExtraButton"
5-
Width="40" RenderTransformOrigin="0.5,0.5" ToolTipService.Placement="Left" ToolTipService.VerticalOffset="16" ToolTipService.HorizontalOffset="-8" Height="0" Cursor="Hand">
5+
Width="40" RenderTransformOrigin="0.5,0.5" ToolTipService.Placement="Left" ToolTipService.VerticalOffset="16" ToolTipService.HorizontalOffset="-8" Height="0">
66
<Grid.RenderTransform>
77
<ScaleTransform ScaleX="0" ScaleY="0" />
88
</Grid.RenderTransform>

Plain Craft Launcher 2/Controls/MyIconTextButton.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Border x:Name="PanBack" x:Class="MyIconTextButton"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
HorizontalAlignment="Center" VerticalAlignment="Center" Background="{StaticResource ColorBrushSemiTransparent}" CornerRadius="13.5" MinHeight="27" MaxHeight="27" Cursor="Hand">
4+
HorizontalAlignment="Center" VerticalAlignment="Center" Background="{StaticResource ColorBrushSemiTransparent}" CornerRadius="13.5" MinHeight="27" MaxHeight="27">
55
<StackPanel Orientation="Horizontal">
66
<Path x:Name="ShapeLogo" HorizontalAlignment="Left" RenderTransformOrigin="0.5,0.5" Margin="12,0,0,0" Stretch="Uniform" Fill="White" MaxHeight="16" MaxWidth="16" VerticalAlignment="Center" />
77
<TextBlock x:Name="LabText" VerticalAlignment="Center" Grid.Column="1" Foreground="White" Margin="7,0,12,1" Grid.ColumnSpan="2" SnapsToDevicePixels="False" UseLayoutRounding="False" />

Plain Craft Launcher 2/Controls/MyImage.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
End If
113113
'从缓存加载网络图片
114114
Dim EnableCache As Boolean = Me.EnableCache
115-
Dim TempPath As String = $"{PathTemp}MyImage\{GetHash(Source)}.png{If(EnableCache, "", GetUuid())}" '不启用缓存时在末尾加上随机字符串,避免冲突
115+
Dim TempPath As String = $"{PathTemp}MyImage\{Source.GetStableHashCode()}.png{If(EnableCache, "", GetUuid())}" '不启用缓存时在末尾加上随机字符串,避免冲突
116116
Dim TempFile = FileUtils.GetInfo(TempPath)
117117
If EnableCache AndAlso TempFile.Exists Then
118118
ActualSource = TempPath '显示缓存的图片

Plain Craft Launcher 2/Controls/MyListItem.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
x:Name="PanBack"
5-
RenderTransformOrigin="0.5,0.5" Background="{StaticResource ColorBrushSemiTransparent}" Height="42" Cursor="Hand">
5+
RenderTransformOrigin="0.5,0.5" Background="{StaticResource ColorBrushSemiTransparent}" Height="42">
66
<Grid.RenderTransform>
77
<ScaleTransform ScaleX="1" ScaleY="1" />
88
</Grid.RenderTransform>

Plain Craft Launcher 2/Controls/MyRadioBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
FocusVisualStyle="{x:Null}"
5-
MinWidth="20" x:Name="PanBack" UseLayoutRounding="False" SnapsToDevicePixels="False" MinHeight="20" Background="{StaticResource ColorBrushSemiTransparent}" Focusable="True" Cursor="Hand">
5+
MinWidth="20" x:Name="PanBack" UseLayoutRounding="False" SnapsToDevicePixels="False" MinHeight="20" Background="{StaticResource ColorBrushSemiTransparent}" Focusable="True">
66
<TextBlock IsHitTestVisible="False" x:Name="LabText" FontSize="13" Padding="0" Margin="26,0,0,0" Foreground="{DynamicResource ColorBrush1}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
77
<Ellipse IsHitTestVisible="False" x:Name="ShapeBorder" StrokeThickness="1.1" HorizontalAlignment="Left" VerticalAlignment="Center" Width="18" Height="18" Stroke="{DynamicResource ColorBrush1}" Margin="1,0,0,0" Fill="{StaticResource ColorBrushHalfWhite}" />
88
<Ellipse IsHitTestVisible="False" x:Name="ShapeDot" HorizontalAlignment="Left" VerticalAlignment="Center" Fill="{Binding Stroke, ElementName=ShapeBorder}" Width="0" Height="0" Margin="10,0,0,0" StrokeThickness="0" />

0 commit comments

Comments
 (0)