mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Data directory changes (#10)
* Data Directory Changes 1. Have implemented a new data directory selection window. 2. Have removed the data directory move button from global settings. * Added restart message
This commit is contained in:
parent
d4b8b51362
commit
b0bced67a7
18 changed files with 626 additions and 123 deletions
|
|
@ -208,6 +208,9 @@
|
|||
<DependentUpon>AddUserWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Lib\Model\StatsMultiplierArray.cs" />
|
||||
<Compile Include="Windows\DataDirectoryWindow.xaml.cs">
|
||||
<DependentUpon>DataDirectoryWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Windows\PlayerListWindow.xaml.cs">
|
||||
<DependentUpon>PlayerListWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
|
@ -391,6 +394,10 @@
|
|||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Windows\DataDirectoryWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Windows\PlayerListWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
|
|
|||
|
|
@ -344,6 +344,9 @@
|
|||
<setting name="VersionFile" serializeAs="String">
|
||||
<value>version.txt</value>
|
||||
</setting>
|
||||
<setting name="DefaultDataDirectoryName" serializeAs="String">
|
||||
<value>asmdata</value>
|
||||
</setting>
|
||||
</ServerManagerTool.Config>
|
||||
<ServerManagerTool.Common.CommonConfig>
|
||||
<setting name="DefaultSteamAPIKey" serializeAs="String">
|
||||
|
|
|
|||
|
|
@ -410,69 +410,15 @@ namespace ServerManagerTool
|
|||
|
||||
ApplicationStarted = true;
|
||||
|
||||
// Initial configuration setting
|
||||
if (String.IsNullOrWhiteSpace(Config.Default.DataDir))
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("Application_DataDirectoryLabel"), _globalizer.GetResourceString("Application_DataDirectoryTitle"), MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
if (string.IsNullOrWhiteSpace(Config.Default.DataDir))
|
||||
{
|
||||
var dataDirectoryWindow = new DataDirectoryWindow();
|
||||
dataDirectoryWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
var result = dataDirectoryWindow.ShowDialog();
|
||||
|
||||
var installationFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
if (!installationFolder.EndsWith(@"\"))
|
||||
installationFolder += @"\";
|
||||
|
||||
var desktopFolder1 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
var desktopFolder2 = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
|
||||
|
||||
while (String.IsNullOrWhiteSpace(Config.Default.DataDir))
|
||||
if (!result.HasValue || !result.Value)
|
||||
{
|
||||
var dialog = new CommonOpenFileDialog
|
||||
{
|
||||
EnsureFileExists = true,
|
||||
IsFolderPicker = true,
|
||||
Multiselect = false,
|
||||
Title = _globalizer.GetResourceString("Application_DataDirectory_DialogTitle"),
|
||||
InitialDirectory = Path.GetPathRoot(installationFolder)
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() != CommonFileDialogResult.Ok)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
MessageBoxResult confirm = MessageBoxResult.Cancel;
|
||||
|
||||
// check if the folder is under the installation folder
|
||||
var newDataFolder = dialog.FileName;
|
||||
if (!newDataFolder.EndsWith(@"\"))
|
||||
newDataFolder += @"\";
|
||||
|
||||
if (newDataFolder.StartsWith(installationFolder))
|
||||
{
|
||||
confirm = MessageBoxResult.No;
|
||||
MessageBox.Show(_globalizer.GetResourceString("Application_DataDirectory_DataDirectoryWithinInstallFolderErrorLabel"), _globalizer.GetResourceString("Application_DataDirectory_DataDirectoryFolderErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else if (newDataFolder.StartsWith(desktopFolder1) || newDataFolder.StartsWith(desktopFolder2))
|
||||
{
|
||||
confirm = MessageBoxResult.No;
|
||||
MessageBox.Show(_globalizer.GetResourceString("Application_DataDirectory_DataDirectoryWithinDesktopFolderErrorLabel"), _globalizer.GetResourceString("Application_DataDirectory_DataDirectoryFolderErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm = MessageBox.Show(String.Format(_globalizer.GetResourceString("Application_DataDirectory_ConfirmLabel"), Path.Combine(newDataFolder, Config.Default.ProfilesDir), Path.Combine(newDataFolder, Config.Default.SteamCmdDir)), _globalizer.GetResourceString("Application_DataDirectory_ConfirmTitle"), MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
||||
}
|
||||
|
||||
if (confirm == MessageBoxResult.Cancel)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
else if (confirm == MessageBoxResult.Yes)
|
||||
{
|
||||
if (newDataFolder.EndsWith(@"\"))
|
||||
newDataFolder = newDataFolder.Substring(0, newDataFolder.Length -1);
|
||||
|
||||
Config.Default.DataDir = newDataFolder;
|
||||
ReconfigureLogging();
|
||||
break;
|
||||
}
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
9
src/ARKServerManager/Config.Designer.cs
generated
9
src/ARKServerManager/Config.Designer.cs
generated
|
|
@ -2803,5 +2803,14 @@ namespace ServerManagerTool {
|
|||
this["MainWindow_Top"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("asmdata")]
|
||||
public string DefaultDataDirectoryName {
|
||||
get {
|
||||
return ((string)(this["DefaultDataDirectoryName"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -776,5 +776,8 @@
|
|||
<Setting Name="MainWindow_Top" Type="System.Double" Scope="User">
|
||||
<Value Profile="(Default)">50</Value>
|
||||
</Setting>
|
||||
<Setting Name="DefaultDataDirectoryName" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">asmdata</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
|
|
@ -165,6 +165,25 @@
|
|||
<sys:String x:Key="ProcessorAffinity_DescriptionColumnLabel">Processor</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--#region Data Directory Window -->
|
||||
<sys:String x:Key="DataDirectory_Title">Data Folder Selection</sys:String>
|
||||
<sys:String x:Key="DataDirectory_InformationLabel">It appears you do not have a data directory set. The data directory is where your profiles and SteamCMD will be stored. It is not the same as the server installation directory, which you can choose for each profile.</sys:String>
|
||||
<sys:String x:Key="DataDirectory_SelectionLabel">Select the drive where the data folder should be located.</sys:String>
|
||||
<sys:String x:Key="DataDirectory_FolderLabel">Data Folder Name:</sys:String>
|
||||
<sys:String x:Key="DataDirectory_FolderTooltip">The name of the server manager data folder.</sys:String>
|
||||
<sys:String x:Key="DataDirectory_LocalDiskLabel">Local Disk</sys:String>
|
||||
<sys:String x:Key="DataDirectory_DriveLine2Label">{0} free of {1}</sys:String>
|
||||
|
||||
<sys:String x:Key="DataDirectory_OkButtonLabel">Ok</sys:String>
|
||||
<sys:String x:Key="DataDirectory_CancelButtonLabel">Cancel</sys:String>
|
||||
<sys:String x:Key="DataDirectory_RefreshButtonLabel">Refresh</sys:String>
|
||||
|
||||
<sys:String x:Key="DataDirectory_ErrorTitle">Data Directory Selection Error</sys:String>
|
||||
<sys:String x:Key="DataDirectory_FolderErrorLabel">The data folder name you have entered is not valid.</sys:String>
|
||||
<sys:String x:Key="DataDirectory_RestartTitle">Server Manager Restart Required</sys:String>
|
||||
<sys:String x:Key="DataDirectory_RestartLabel">The data folder has been set, you must now restart the server manager to use the new settings.</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--#region PlayerListWindow Window -->
|
||||
<sys:String x:Key="PlayerList_CloseButtonLabel">Close</sys:String>
|
||||
|
||||
|
|
|
|||
95
src/ARKServerManager/Windows/DataDirectoryWindow.xaml
Normal file
95
src/ARKServerManager/Windows/DataDirectoryWindow.xaml
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<Window x:Class="ServerManagerTool.Windows.DataDirectoryWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
MinHeight="400" MinWidth="500" Height="400" Width="500" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="True" ResizeMode="CanResize"
|
||||
Icon="../Art/favicon.ico" Title="{DynamicResource DataDirectory_Title}"
|
||||
x:Name="DataDirectory">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="..\Globalization\en-US\en-US.xaml"/>
|
||||
<ResourceDictionary Source="..\Styles\Default.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid Background="{StaticResource GradientBackground}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Margin="5" Text="{DynamicResource DataDirectory_InformationLabel}" Foreground="DarkCyan" VerticalAlignment="Center" TextWrapping="Wrap" />
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="5" Text="{DynamicResource DataDirectory_SelectionLabel}" FontWeight="Bold" VerticalAlignment="Center" TextWrapping="Wrap" />
|
||||
|
||||
<ListBox x:Name="DriveSelectionListBox" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Margin="5" ItemsSource="{Binding DriveInformation, ElementName=DataDirectory}" HorizontalContentAlignment="Stretch" Background="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}">
|
||||
<ListBox.Resources>
|
||||
<Style TargetType="{x:Type ListBoxItem}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ListBoxItem}">
|
||||
<Border x:Name="Bd"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Background="{TemplateBinding Background}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="true">
|
||||
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="Selector.IsSelectionActive" Value="False" />
|
||||
<Condition Property="IsSelected" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
|
||||
</MultiTrigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="Selector.IsSelectionActive" Value="True" />
|
||||
<Condition Property="IsSelected" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ListBox.Resources>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border BorderBrush="Black" BorderThickness="1">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Grid.Row="0" Content="{Binding Line1}" FontSize="12" FontWeight="Bold" VerticalAlignment="Center" Padding="5,5,5,0"/>
|
||||
<Label Grid.Row="1" Content="{Binding Line2}" VerticalAlignment="Center" Padding="5,0,5,5"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<Label Grid.Row="3" Grid.Column="0" Content="{DynamicResource DataDirectory_FolderLabel}" ToolTip="{DynamicResource DataDirectory_FolderTooltip}" />
|
||||
<TextBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,5,0" Text="{Binding FolderName, ElementName=DataDirectory, Mode=TwoWay}" VerticalContentAlignment="Center" MaxLength="50" ToolTip="{DynamicResource DataDirectory_FolderTooltip}" />
|
||||
|
||||
<Button Grid.Row="4" Grid.Column="0" Content="{DynamicResource DataDirectory_RefreshButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Left" Click="Refresh_Click" Visibility="Hidden"/>
|
||||
<Button Grid.Row="4" Grid.Column="1" Content="{DynamicResource DataDirectory_OkButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Right" Click="Ok_Click"/>
|
||||
<Button Grid.Row="4" Grid.Column="2" Content="{DynamicResource DataDirectory_CancelButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Left" IsCancel="True"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
169
src/ARKServerManager/Windows/DataDirectoryWindow.xaml.cs
Normal file
169
src/ARKServerManager/Windows/DataDirectoryWindow.xaml.cs
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using WPFSharp.Globalizer;
|
||||
|
||||
namespace ServerManagerTool.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DriveSelectionWindow.xaml
|
||||
/// </summary>
|
||||
public partial class DataDirectoryWindow : Window
|
||||
{
|
||||
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
|
||||
public static readonly DependencyProperty DriveInformationProperty = DependencyProperty.Register(nameof(DriveInformation), typeof(List<DriveInfoDisplay>), typeof(DataDirectoryWindow), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty FolderNameProperty = DependencyProperty.Register(nameof(FolderName), typeof(string), typeof(DataDirectoryWindow), new PropertyMetadata(null));
|
||||
|
||||
public DataDirectoryWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
PopulateDriveInformation();
|
||||
}
|
||||
|
||||
public List<DriveInfoDisplay> DriveInformation
|
||||
{
|
||||
get { return (List<DriveInfoDisplay>)GetValue(DriveInformationProperty); }
|
||||
set { SetValue(DriveInformationProperty, value); }
|
||||
}
|
||||
|
||||
public string FolderName
|
||||
{
|
||||
get { return (string)GetValue(FolderNameProperty); }
|
||||
set { SetValue(FolderNameProperty, value); }
|
||||
}
|
||||
|
||||
private void PopulateDriveInformation()
|
||||
{
|
||||
this.FolderName = Config.Default.DefaultDataDirectoryName;
|
||||
this.DriveInformation = DriveInfo.GetDrives().Where(d => d.IsReady && d.DriveType == DriveType.Fixed).Select(d => new DriveInfoDisplay(d)).ToList();
|
||||
|
||||
var installationFolder = Path.GetPathRoot(Assembly.GetEntryAssembly().Location);
|
||||
if (!installationFolder.EndsWith(@"\"))
|
||||
installationFolder += @"\";
|
||||
|
||||
foreach (var driveInfo in DriveInformation)
|
||||
{
|
||||
if (driveInfo.DriveInfo.RootDirectory.FullName.Equals(installationFolder))
|
||||
{
|
||||
this.DriveSelectionListBox.SelectedItem = driveInfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Ok_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = CreateDataDirectory();
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("DataDirectory_RestartLabel"), _globalizer.GetResourceString("DataDirectory_RestartTitle"), MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
this.DialogResult = true;
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, _globalizer.GetResourceString("DataDirectory_ErrorTitle"));
|
||||
}
|
||||
}
|
||||
|
||||
private void Refresh_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PopulateDriveInformation();
|
||||
}
|
||||
|
||||
private MessageBoxResult CreateDataDirectory()
|
||||
{
|
||||
var selectedDrive = this.DriveSelectionListBox.SelectedItem as DriveInfoDisplay;
|
||||
if (selectedDrive is null)
|
||||
{
|
||||
return MessageBoxResult.None;
|
||||
}
|
||||
|
||||
var invalidCharacters = Path.GetInvalidFileNameChars();
|
||||
if (string.IsNullOrWhiteSpace(FolderName) || FolderName.Any(c => invalidCharacters.Contains(c)))
|
||||
{
|
||||
throw new Exception(_globalizer.GetResourceString("DataDirectory_FolderErrorLabel"));
|
||||
}
|
||||
|
||||
var newDataFolder = Path.Combine(selectedDrive.DriveInfo.RootDirectory.FullName, FolderName);
|
||||
|
||||
var confirm = MessageBox.Show(string.Format(_globalizer.GetResourceString("Application_DataDirectory_ConfirmLabel"), Path.Combine(newDataFolder, Config.Default.ProfilesDir), Path.Combine(newDataFolder, Config.Default.SteamCmdDir)), _globalizer.GetResourceString("Application_DataDirectory_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (confirm == MessageBoxResult.Yes)
|
||||
{
|
||||
if (newDataFolder.EndsWith(@"\"))
|
||||
newDataFolder = newDataFolder.Substring(0, newDataFolder.Length - 1);
|
||||
|
||||
Config.Default.DataDir = newDataFolder;
|
||||
}
|
||||
|
||||
return confirm;
|
||||
}
|
||||
}
|
||||
|
||||
public class DriveInfoDisplay
|
||||
{
|
||||
private const decimal DIVISOR = 1024M;
|
||||
|
||||
// Load all suffixes in an array
|
||||
private static readonly string[] suffixes = { "Bytes", "KB", "MB", "GB", "TB", "PB" };
|
||||
|
||||
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
|
||||
public DriveInfoDisplay(DriveInfo driveInfo)
|
||||
{
|
||||
DriveInfo = driveInfo;
|
||||
}
|
||||
|
||||
public DriveInfo DriveInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Line1
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DriveInfo is null)
|
||||
return string.Empty;
|
||||
|
||||
var volumeLabel = string.IsNullOrWhiteSpace(DriveInfo.VolumeLabel) ? _globalizer.GetResourceString("DataDirectory_LocalDiskLabel") : DriveInfo.VolumeLabel;
|
||||
return $"{volumeLabel} ({DriveInfo.Name.Replace(@"\", string.Empty)})";
|
||||
}
|
||||
}
|
||||
|
||||
public string Line2
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DriveInfo is null)
|
||||
return string.Empty;
|
||||
|
||||
return string.Format(_globalizer.GetResourceString("DataDirectory_DriveLine2Label"), FormatSize(DriveInfo.TotalFreeSpace), FormatSize(DriveInfo.TotalSize));
|
||||
}
|
||||
}
|
||||
|
||||
public static string FormatSize(long bytes)
|
||||
{
|
||||
var counter = 0;
|
||||
var number = (decimal)bytes;
|
||||
|
||||
while (number / DIVISOR >= 1)
|
||||
{
|
||||
number /= DIVISOR;
|
||||
counter++;
|
||||
}
|
||||
|
||||
return string.Format("{0:n2} {1}", number, suffixes[counter]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
<Label Grid.Row="4" Grid.Column="0" Margin="1" Content="{DynamicResource GlobalSettings_DataDirectoryLabel}" VerticalAlignment="Center"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="1" Text="{Binding CurrentConfig.DataDir, Mode=TwoWay}" IsReadOnly="True" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center" />
|
||||
<Button Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2" Margin="5,1,0,1" VerticalAlignment="Center" HorizontalAlignment="Left" Content="{DynamicResource DataDirectoryButtonContent}" Click="SetDataDir_Click"/>
|
||||
<Button Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2" Margin="5,1,0,1" VerticalAlignment="Center" HorizontalAlignment="Left" Content="{DynamicResource DataDirectoryButtonContent}" Click="SetDataDir_Click" Visibility="Hidden"/>
|
||||
|
||||
<Label Grid.Row="5" Grid.Column="0" Margin="1" Content="{DynamicResource GlobalSettings_BackupDirectoryLabel}" VerticalAlignment="Center"/>
|
||||
<TextBox Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" Margin="1" Text="{Binding CurrentConfig.BackupPath, Mode=TwoWay}" IsReadOnly="True" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center"/>
|
||||
|
|
|
|||
|
|
@ -254,6 +254,9 @@
|
|||
<setting name="ServerStatusWatcher_RemoteStatusQueryDelay" serializeAs="String">
|
||||
<value>120000</value>
|
||||
</setting>
|
||||
<setting name="DefaultDataDirectoryName" serializeAs="String">
|
||||
<value>csmdata</value>
|
||||
</setting>
|
||||
</ServerManagerTool.Config>
|
||||
<ServerManagerTool.Common.CommonConfig>
|
||||
<setting name="DefaultSteamAPIKey" serializeAs="String">
|
||||
|
|
|
|||
|
|
@ -393,69 +393,15 @@ namespace ServerManagerTool
|
|||
|
||||
this.ApplicationStarted = true;
|
||||
|
||||
// Initial configuration setting
|
||||
if (String.IsNullOrWhiteSpace(Config.Default.DataPath))
|
||||
if (string.IsNullOrWhiteSpace(Config.Default.DataPath))
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("Application_DataDirectoryLabel"), _globalizer.GetResourceString("Application_DataDirectoryTitle"), MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
var dataDirectoryWindow = new DataDirectoryWindow();
|
||||
dataDirectoryWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
var result = dataDirectoryWindow.ShowDialog();
|
||||
|
||||
var installationFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
if (!installationFolder.EndsWith(@"\"))
|
||||
installationFolder += @"\";
|
||||
|
||||
var desktopFolder1 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
var desktopFolder2 = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
|
||||
|
||||
while (String.IsNullOrWhiteSpace(Config.Default.DataPath))
|
||||
if (!result.HasValue || !result.Value)
|
||||
{
|
||||
var dialog = new CommonOpenFileDialog
|
||||
{
|
||||
EnsureFileExists = true,
|
||||
IsFolderPicker = true,
|
||||
Multiselect = false,
|
||||
Title = _globalizer.GetResourceString("Application_DataDirectory_DialogTitle"),
|
||||
InitialDirectory = Path.GetPathRoot(installationFolder)
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() != CommonFileDialogResult.Ok)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
MessageBoxResult confirm = MessageBoxResult.Cancel;
|
||||
|
||||
// check if the folder is under the installation folder
|
||||
var newDataFolder = dialog.FileName;
|
||||
if (!newDataFolder.EndsWith(@"\"))
|
||||
newDataFolder += @"\";
|
||||
|
||||
if (newDataFolder.StartsWith(installationFolder))
|
||||
{
|
||||
confirm = MessageBoxResult.No;
|
||||
MessageBox.Show(_globalizer.GetResourceString("Application_DataDirectory_DataDirectoryWithinInstallFolderErrorLabel"), _globalizer.GetResourceString("Application_DataDirectory_DataDirectoryFolderErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else if (newDataFolder.StartsWith(desktopFolder1) || newDataFolder.StartsWith(desktopFolder2))
|
||||
{
|
||||
confirm = MessageBoxResult.No;
|
||||
MessageBox.Show(_globalizer.GetResourceString("Application_DataDirectory_DataDirectoryWithinDesktopFolderErrorLabel"), _globalizer.GetResourceString("Application_DataDirectory_DataDirectoryFolderErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm = MessageBox.Show(String.Format(_globalizer.GetResourceString("Application_DataDirectory_ConfirmLabel"), Path.Combine(newDataFolder, Config.Default.ProfilesRelativePath), Path.Combine(newDataFolder, CommonConfig.Default.SteamCmdRelativePath)), _globalizer.GetResourceString("Application_DataDirectory_ConfirmTitle"), MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
||||
}
|
||||
|
||||
if (confirm == MessageBoxResult.Cancel)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
else if (confirm == MessageBoxResult.Yes)
|
||||
{
|
||||
if (newDataFolder.EndsWith(@"\"))
|
||||
newDataFolder = newDataFolder.Substring(0, newDataFolder.Length - 1);
|
||||
|
||||
Config.Default.DataPath = newDataFolder;
|
||||
ReconfigureLogging();
|
||||
break;
|
||||
}
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -180,6 +180,9 @@
|
|||
<Compile Include="Windows\CommandLineWindow.xaml.cs">
|
||||
<DependentUpon>CommandLineWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Windows\DataDirectoryWindow.xaml.cs">
|
||||
<DependentUpon>DataDirectoryWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Windows\GameDataWindow.xaml.cs">
|
||||
<DependentUpon>GameDataWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
|
@ -305,6 +308,10 @@
|
|||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Windows\DataDirectoryWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Windows\GameDataWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
|
|
|
|||
9
src/ConanServerManager/Config.Designer.cs
generated
9
src/ConanServerManager/Config.Designer.cs
generated
|
|
@ -1956,5 +1956,14 @@ namespace ServerManagerTool {
|
|||
this["ServerFilesGridHeight"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("csmdata")]
|
||||
public string DefaultDataDirectoryName {
|
||||
get {
|
||||
return ((string)(this["DefaultDataDirectoryName"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -542,5 +542,8 @@
|
|||
<Setting Name="ServerFilesGridHeight" Type="System.Windows.GridLength" Scope="User">
|
||||
<Value Profile="(Default)">250</Value>
|
||||
</Setting>
|
||||
<Setting Name="DefaultDataDirectoryName" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">csmdata</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
|
|
@ -168,6 +168,25 @@
|
|||
<sys:String x:Key="ProcessorAffinity_DescriptionColumnLabel">Processor</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--#region Data Directory Window -->
|
||||
<sys:String x:Key="DataDirectory_Title">Data Folder Selection</sys:String>
|
||||
<sys:String x:Key="DataDirectory_InformationLabel">It appears you do not have a data directory set. The data directory is where your profiles and SteamCMD will be stored. It is not the same as the server installation directory, which you can choose for each profile.</sys:String>
|
||||
<sys:String x:Key="DataDirectory_SelectionLabel">Select the drive where the data folder should be located.</sys:String>
|
||||
<sys:String x:Key="DataDirectory_FolderLabel">Data Folder Name:</sys:String>
|
||||
<sys:String x:Key="DataDirectory_FolderTooltip">The name of the server manager data folder.</sys:String>
|
||||
<sys:String x:Key="DataDirectory_LocalDiskLabel">Local Disk</sys:String>
|
||||
<sys:String x:Key="DataDirectory_DriveLine2Label">{0} free of {1}</sys:String>
|
||||
|
||||
<sys:String x:Key="DataDirectory_OkButtonLabel">Ok</sys:String>
|
||||
<sys:String x:Key="DataDirectory_CancelButtonLabel">Cancel</sys:String>
|
||||
<sys:String x:Key="DataDirectory_RefreshButtonLabel">Refresh</sys:String>
|
||||
|
||||
<sys:String x:Key="DataDirectory_ErrorTitle">Data Directory Selection Error</sys:String>
|
||||
<sys:String x:Key="DataDirectory_FolderErrorLabel">The data folder name you have entered is not valid.</sys:String>
|
||||
<sys:String x:Key="DataDirectory_RestartTitle">Server Manager Restart Required</sys:String>
|
||||
<sys:String x:Key="DataDirectory_RestartLabel">The data folder has been set, you must now restart the server manager to use the new settings.</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--#region Mod Details Window -->
|
||||
<sys:String x:Key="ModDetails_Title">Mod Details</sys:String>
|
||||
<sys:String x:Key="ModDetails_ProfileTitle">Mod Details - {0}</sys:String>
|
||||
|
|
|
|||
95
src/ConanServerManager/Windows/DataDirectoryWindow.xaml
Normal file
95
src/ConanServerManager/Windows/DataDirectoryWindow.xaml
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<Window x:Class="ServerManagerTool.Windows.DataDirectoryWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
MinHeight="400" MinWidth="500" Height="400" Width="500" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="True" ResizeMode="CanResize"
|
||||
Icon="../Art/favicon.ico" Title="{DynamicResource DataDirectory_Title}"
|
||||
x:Name="DataDirectory">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="..\Globalization\en-US\en-US.xaml"/>
|
||||
<ResourceDictionary Source="..\Styles\Default.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid Background="{StaticResource GradientBackground}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Margin="5" Text="{DynamicResource DataDirectory_InformationLabel}" Foreground="DarkCyan" VerticalAlignment="Center" TextWrapping="Wrap" />
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="5" Text="{DynamicResource DataDirectory_SelectionLabel}" FontWeight="Bold" VerticalAlignment="Center" TextWrapping="Wrap" />
|
||||
|
||||
<ListBox x:Name="DriveSelectionListBox" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Margin="5" ItemsSource="{Binding DriveInformation, ElementName=DataDirectory}" HorizontalContentAlignment="Stretch" Background="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}">
|
||||
<ListBox.Resources>
|
||||
<Style TargetType="{x:Type ListBoxItem}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ListBoxItem}">
|
||||
<Border x:Name="Bd"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Background="{TemplateBinding Background}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="true">
|
||||
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="Selector.IsSelectionActive" Value="False" />
|
||||
<Condition Property="IsSelected" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
|
||||
</MultiTrigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="Selector.IsSelectionActive" Value="True" />
|
||||
<Condition Property="IsSelected" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ListBox.Resources>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border BorderBrush="Black" BorderThickness="1">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Grid.Row="0" Content="{Binding Line1}" FontSize="12" FontWeight="Bold" VerticalAlignment="Center" Padding="5,5,5,0"/>
|
||||
<Label Grid.Row="1" Content="{Binding Line2}" VerticalAlignment="Center" Padding="5,0,5,5"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<Label Grid.Row="3" Grid.Column="0" Content="{DynamicResource DataDirectory_FolderLabel}" ToolTip="{DynamicResource DataDirectory_FolderTooltip}" />
|
||||
<TextBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,5,0" Text="{Binding FolderName, ElementName=DataDirectory, Mode=TwoWay}" VerticalContentAlignment="Center" MaxLength="50" ToolTip="{DynamicResource DataDirectory_FolderTooltip}" />
|
||||
|
||||
<Button Grid.Row="4" Grid.Column="0" Content="{DynamicResource DataDirectory_RefreshButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Left" Click="Refresh_Click" Visibility="Hidden"/>
|
||||
<Button Grid.Row="4" Grid.Column="1" Content="{DynamicResource DataDirectory_OkButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Right" Click="Ok_Click"/>
|
||||
<Button Grid.Row="4" Grid.Column="2" Content="{DynamicResource DataDirectory_CancelButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Left" IsCancel="True"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
170
src/ConanServerManager/Windows/DataDirectoryWindow.xaml.cs
Normal file
170
src/ConanServerManager/Windows/DataDirectoryWindow.xaml.cs
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
using ServerManagerTool.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using WPFSharp.Globalizer;
|
||||
|
||||
namespace ServerManagerTool.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DriveSelectionWindow.xaml
|
||||
/// </summary>
|
||||
public partial class DataDirectoryWindow : Window
|
||||
{
|
||||
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
|
||||
public static readonly DependencyProperty DriveInformationProperty = DependencyProperty.Register(nameof(DriveInformation), typeof(List<DriveInfoDisplay>), typeof(DataDirectoryWindow), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty FolderNameProperty = DependencyProperty.Register(nameof(FolderName), typeof(string), typeof(DataDirectoryWindow), new PropertyMetadata(null));
|
||||
|
||||
public DataDirectoryWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
PopulateDriveInformation();
|
||||
}
|
||||
|
||||
public List<DriveInfoDisplay> DriveInformation
|
||||
{
|
||||
get { return (List<DriveInfoDisplay>)GetValue(DriveInformationProperty); }
|
||||
set { SetValue(DriveInformationProperty, value); }
|
||||
}
|
||||
|
||||
public string FolderName
|
||||
{
|
||||
get { return (string)GetValue(FolderNameProperty); }
|
||||
set { SetValue(FolderNameProperty, value); }
|
||||
}
|
||||
|
||||
private void PopulateDriveInformation()
|
||||
{
|
||||
this.FolderName = Config.Default.DefaultDataDirectoryName;
|
||||
this.DriveInformation = DriveInfo.GetDrives().Where(d => d.IsReady && d.DriveType == DriveType.Fixed).Select(d => new DriveInfoDisplay(d)).ToList();
|
||||
|
||||
var installationFolder = Path.GetPathRoot(Assembly.GetEntryAssembly().Location);
|
||||
if (!installationFolder.EndsWith(@"\"))
|
||||
installationFolder += @"\";
|
||||
|
||||
foreach (var driveInfo in DriveInformation)
|
||||
{
|
||||
if (driveInfo.DriveInfo.RootDirectory.FullName.Equals(installationFolder))
|
||||
{
|
||||
this.DriveSelectionListBox.SelectedItem = driveInfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Ok_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = CreateDataDirectory();
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("DataDirectory_RestartLabel"), _globalizer.GetResourceString("DataDirectory_RestartTitle"), MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
this.DialogResult = true;
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, _globalizer.GetResourceString("DataDirectory_ErrorTitle"));
|
||||
}
|
||||
}
|
||||
|
||||
private void Refresh_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PopulateDriveInformation();
|
||||
}
|
||||
|
||||
private MessageBoxResult CreateDataDirectory()
|
||||
{
|
||||
var selectedDrive = this.DriveSelectionListBox.SelectedItem as DriveInfoDisplay;
|
||||
if (selectedDrive is null)
|
||||
{
|
||||
return MessageBoxResult.None;
|
||||
}
|
||||
|
||||
var invalidCharacters = Path.GetInvalidFileNameChars();
|
||||
if (string.IsNullOrWhiteSpace(FolderName) || FolderName.Any(c => invalidCharacters.Contains(c)))
|
||||
{
|
||||
throw new Exception(_globalizer.GetResourceString("DataDirectory_FolderErrorLabel"));
|
||||
}
|
||||
|
||||
var newDataFolder = Path.Combine(selectedDrive.DriveInfo.RootDirectory.FullName, FolderName);
|
||||
|
||||
var confirm = MessageBox.Show(string.Format(_globalizer.GetResourceString("Application_DataDirectory_ConfirmLabel"), Path.Combine(newDataFolder, Config.Default.ProfilesRelativePath), Path.Combine(newDataFolder, CommonConfig.Default.SteamCmdRelativePath)), _globalizer.GetResourceString("Application_DataDirectory_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (confirm == MessageBoxResult.Yes)
|
||||
{
|
||||
if (newDataFolder.EndsWith(@"\"))
|
||||
newDataFolder = newDataFolder.Substring(0, newDataFolder.Length - 1);
|
||||
|
||||
Config.Default.DataPath = newDataFolder;
|
||||
}
|
||||
|
||||
return confirm;
|
||||
}
|
||||
}
|
||||
|
||||
public class DriveInfoDisplay
|
||||
{
|
||||
private const decimal DIVISOR = 1024M;
|
||||
|
||||
// Load all suffixes in an array
|
||||
private static readonly string[] suffixes = { "Bytes", "KB", "MB", "GB", "TB", "PB" };
|
||||
|
||||
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
|
||||
public DriveInfoDisplay(DriveInfo driveInfo)
|
||||
{
|
||||
DriveInfo = driveInfo;
|
||||
}
|
||||
|
||||
public DriveInfo DriveInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Line1
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DriveInfo is null)
|
||||
return string.Empty;
|
||||
|
||||
var volumeLabel = string.IsNullOrWhiteSpace(DriveInfo.VolumeLabel) ? _globalizer.GetResourceString("DataDirectory_LocalDiskLabel") : DriveInfo.VolumeLabel;
|
||||
return $"{volumeLabel} ({DriveInfo.Name.Replace(@"\", string.Empty)})";
|
||||
}
|
||||
}
|
||||
|
||||
public string Line2
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DriveInfo is null)
|
||||
return string.Empty;
|
||||
|
||||
return string.Format(_globalizer.GetResourceString("DataDirectory_DriveLine2Label"), FormatSize(DriveInfo.TotalFreeSpace), FormatSize(DriveInfo.TotalSize));
|
||||
}
|
||||
}
|
||||
|
||||
public static string FormatSize(long bytes)
|
||||
{
|
||||
var counter = 0;
|
||||
var number = (decimal)bytes;
|
||||
|
||||
while (number / DIVISOR >= 1)
|
||||
{
|
||||
number /= DIVISOR;
|
||||
counter++;
|
||||
}
|
||||
|
||||
return string.Format("{0:n2} {1}", number, suffixes[counter]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@
|
|||
|
||||
<Label Grid.Row="4" Grid.Column="0" Margin="1" Content="{DynamicResource GlobalSettings_DataDirectoryLabel}" VerticalAlignment="Center"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="1" Text="{Binding Config.DataPath, Mode=TwoWay}" IsReadOnly="True" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center" />
|
||||
<Button Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2" Margin="5,1,0,1" VerticalAlignment="Center" HorizontalAlignment="Left" Content="{DynamicResource DataDirectoryButtonContent}" Click="SetDataDir_Click"/>
|
||||
<Button Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2" Margin="5,1,0,1" VerticalAlignment="Center" HorizontalAlignment="Left" Content="{DynamicResource DataDirectoryButtonContent}" Click="SetDataDir_Click" Visibility="Hidden"/>
|
||||
|
||||
<Label Grid.Row="5" Grid.Column="0" Margin="1" Content="{DynamicResource GlobalSettings_BackupDirectoryLabel}" VerticalAlignment="Center"/>
|
||||
<TextBox Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" Margin="1" Text="{Binding Config.BackupPath, Mode=TwoWay}" IsReadOnly="True" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue