Skip to content

Commit e1b88f7

Browse files
committed
WizardWindow: better reduce paths
- add prefix path hash to avoid naming conflicts - choose whether or not to enable the feature in the settings
1 parent e015544 commit e1b88f7

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

OKEGui/OKEGui/Gui/ConfigPanel.xaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:local="clr-namespace:OKEGui"
77
DataContext="{Binding RelativeSource={RelativeSource Self}}"
88
mc:Ignorable="d"
9-
Title="设置" Height="300" Width="500" WindowStartupLocation="CenterScreen" FontFamily="Segoe UI, Microsoft YaHei">
9+
Title="设置" Height="330" Width="500" WindowStartupLocation="CenterScreen" FontFamily="Segoe UI, Microsoft YaHei">
1010
<Window.Resources>
1111
<Style TargetType="DataGridCell">
1212
<Setter Property="HorizontalContentAlignment" Value="Left" />
@@ -16,7 +16,7 @@
1616
<Grid>
1717
<Grid.RowDefinitions>
1818
<RowDefinition Height="70"/>
19-
<RowDefinition Height="105"/>
19+
<RowDefinition Height="135"/>
2020
<RowDefinition/>
2121
</Grid.RowDefinitions>
2222
<Grid Grid.Row="0" Height="70" VerticalAlignment="Top">
@@ -36,7 +36,7 @@
3636
<TextBox Height="25" Grid.Row="1" Grid.Column="1" Text="{Binding Config.rpCheckerPath}"/>
3737
<Button Height="25" Width="40" Grid.Row="1" Grid.Column="2" Content="选择" Click="RPChecker_Click"/>
3838
</Grid>
39-
<Grid Grid.Row="1" Height="105" VerticalAlignment="Top">
39+
<Grid Grid.Row="1" Height="135" VerticalAlignment="Top">
4040
<Grid.ColumnDefinitions>
4141
<ColumnDefinition Width="400"/>
4242
<ColumnDefinition Width="95"/>
@@ -45,6 +45,7 @@
4545
<RowDefinition/>
4646
<RowDefinition/>
4747
<RowDefinition/>
48+
<RowDefinition/>
4849
</Grid.RowDefinitions>
4950
<TextBlock Margin="10,9" Height="30" Grid.Row="0" Grid.Column="0" Text="记录详细程度(从上到下越来越详细)"/>
5051
<ComboBox Height="25" Width="70" Grid.Row="0" HorizontalAlignment="Center" Grid.Column="1" SelectedValue="{Binding Config.logLevel}" SelectedValuePath="Content">
@@ -60,6 +61,8 @@
6061
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1" IsChecked="{Binding Config.singleNuma}"/>
6162
<TextBlock Margin="10,9" Height="30" Grid.Row="2" Grid.Column="0" Text="开启 AVX512 烤鸡模式"/>
6263
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="2" Grid.Column="1" IsChecked="{Binding Config.avx512}"/>
64+
<TextBlock Margin="10,9" Height="30" Grid.Row="3" Grid.Column="0" Text="启用中间文件目录和输出目录路径缩减功能"/>
65+
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="3" Grid.Column="1" IsChecked="{Binding Config.reducePath}"/>
6366
</Grid>
6467
<Grid Grid.Row="2">
6568
<Grid.ColumnDefinitions>

OKEGui/OKEGui/Gui/WizardWindow.xaml.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,28 @@ private void WizardFinish(object sender, RoutedEventArgs e)
273273
inputSuffixPath = Regex.Replace(inputSuffixPath, @"[/\\]" + Regex.Escape(comp) + @"[/\\]", "\\");
274274
}
275275
string[] inputSuffixComponents = inputSuffixPath.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
276-
if (inputSuffixComponents.Length > 3)
276+
if (inputSuffixComponents.Length > 3 && Initializer.Config.reducePath)
277277
{
278-
string[] newInputSuffixComponents = new string[] {inputSuffixComponents[0], inputSuffixComponents[inputSuffixComponents.Length - 2], inputSuffixComponents[inputSuffixComponents.Length - 1]};
278+
// inputSuffixComponents[0] is drive number, inputSuffixComponents[-1] is filename, inputSuffixComponents[1:-2] is the effective path to be reduced.
279+
string effectivePathPrefix = string.Join("\\", inputSuffixComponents, 1, inputSuffixComponents.Length - 3);
280+
string effectivePathLast = inputSuffixComponents[inputSuffixComponents.Length - 2];
281+
Regex rVolNumber = new Regex(@".*Vol[.\- ]?(?<vol>\d+).*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
282+
Match mLast = rVolNumber.Match(effectivePathLast);
283+
284+
string newEffectivePath;
285+
if (mLast.Success)
286+
{
287+
// If the last level path contains a volume number, keep the last level path unchanged.
288+
newEffectivePath = effectivePathLast;
289+
}
290+
else
291+
{
292+
// By default, the last level path is preserved and the crc of the prefix path is added to prevent naming conflicts.
293+
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(effectivePathPrefix);
294+
var crc = CRC32.Compute(buffer);
295+
newEffectivePath = crc.ToString("X8") + "-" + effectivePathLast;
296+
}
297+
string[] newInputSuffixComponents = new string[] {inputSuffixComponents[0], newEffectivePath, inputSuffixComponents[inputSuffixComponents.Length - 1]};
279298
inputSuffixPath = string.Join("\\", newInputSuffixComponents);
280299
}
281300
Logger.Debug("inputSuffixPathComponents: " + string.Join(", ", inputSuffixComponents));

OKEGui/OKEGui/Utils/Initializer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ public bool avx512
8484
}
8585
}
8686

87+
private bool _reducePath = true;
88+
public bool reducePath
89+
{
90+
get => _reducePath;
91+
set
92+
{
93+
_reducePath = value;
94+
NotifyPropertyChanged();
95+
}
96+
}
97+
8798
private int _memoryLimit;
8899
public int memoryLimit
89100
{

0 commit comments

Comments
 (0)