此次提交主要对代码进行了简化和优化,具体更改如下: 1. 在 `App.xaml` 中,将 `ConCernItem` 的 `DataTemplate` 从 `StackPanel` 改为 `Grid`,并添加了 `Grid.ColumnDefinitions` 和 `Grid.RowDefinitions`。 2. 在 `App.xaml.cs` 中,删除了创建和解压缩 `RustCode` 目录的代码,改为直接从 `Assets` 目录获取 `DataBaseManifest` 文件,并更新了异常处理逻辑。 3. 在 `RustTools.csproj` 中,添加了新的 `PackageReference`,更新了 `RestSharp` 的版本,并注释掉了 `squirrel.windows` 的引用。 4. 在 `PostRwmod.xaml.cs` 中,删除了 `SharpCompress.Common` 和 `TinyPinyin` 的引用。 5. 在 `CodeDataPage.xaml.cs` 中,更新了 `filePath` 的路径,从 `ApplicationData.Current.LocalFolder.Path` 改为 `AppContext.BaseDirectory`。 6. 在 `ConcernPage.xaml` 中,调整了 `StackPanelA` 的 `MinWidth` 属性,并删除了 `StackPanel` 的 `Background` 属性。 7. 在 `ConcernPage.xaml.cs` 中,更新了 `Getlist` 方法的逻辑,增加了对 `response` 的空值和错误码检查。 8. 在 `ModulePage.xaml.cs` 中,删除了 `SharpCompress.Common` 和 `WinRT.Interop` 的引用。 9. 在 `SettingsPage.xaml` 中,更新了 `PersonPicture` 的 `ToolTipService.ToolTip` 属性。 10. 在 `IniHelper.cs` 中,更新了 `Load` 方法的 `filePath` 路径,并添加了目录不存在时创建目录的逻辑。 11. 在 `wj.cs` 中,更新了 `CD` 的路径为 `AppContext.BaseDirectory`,并注释掉了废弃的路径。 12. 在 `config.ini` 中,添加了 `[Settings]` 节点和 `SystemBackdrop=Mica` 设置。 此外,添加了以下新 JSON 文件: 1. `DataBaseManifest.json`:包含数据集的基本信息和数据表的映射。 2. `game_version.json`:包含游戏版本数据。 3. `section.json`:包含铁锈助手节名数据。 4. `value_type.json`:定义了一个名为 "值类型表" 的数据结构,包含多个值类型及其详细信息。
346 lines
10 KiB
C#
346 lines
10 KiB
C#
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Microsoft.UI.Xaml.Controls.Primitives;
|
|
using Microsoft.UI.Xaml.Media;
|
|
using Microsoft.VisualBasic.FileIO;
|
|
using RustTools.muqing;
|
|
using RustTools.Themes;
|
|
using RustTools.ViewModels;
|
|
namespace RustTools.Views;
|
|
/// <summary>
|
|
/// 模组碎片
|
|
/// </summary>
|
|
public class DataObject
|
|
{
|
|
public string Dri
|
|
{
|
|
get; set;
|
|
}
|
|
public string Name
|
|
{
|
|
get; set;
|
|
}
|
|
public string Info
|
|
{
|
|
get; set;
|
|
}
|
|
public bool IsRwmod
|
|
{
|
|
get; set;
|
|
}
|
|
public string Icon
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
#pragma warning disable CS8765 // 参数类型的为 Null 性与重写成员不匹配(可能是由于为 Null 性特性)。
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj is DataObject other)
|
|
{
|
|
return Dri == other.Dri;
|
|
}
|
|
return false;
|
|
}
|
|
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
|
public DataObject(FileInfo fileInfo)
|
|
{
|
|
Name = Path.GetFileNameWithoutExtension(fileInfo.Name);
|
|
//Name = fileInfo.Name;
|
|
IsRwmod = true;
|
|
Info = $"大小:{wj.FormatFileSize(fileInfo.Length)}";
|
|
Dri = fileInfo.FullName;
|
|
}
|
|
public DataObject(DirectoryInfo fileInfo)
|
|
{
|
|
Name = fileInfo.Name;
|
|
IsRwmod = false;
|
|
Info = $"{fileInfo.CreationTime}";
|
|
Dri = fileInfo.FullName;
|
|
Icon = File.Exists(Path.Combine(Dri, "icon.png")) ? Path.Combine(Dri, "icon.png") : "/Assets/image/folder.svg";
|
|
var modinfo = Path.Combine(Dri, "mod-info.txt");
|
|
if (File.Exists(modinfo))
|
|
{
|
|
var dictionary = gj.IniInfo(modinfo);
|
|
if (dictionary.TryGetValue("mod", out var sectionValues))
|
|
{
|
|
gj.sc(sectionValues);
|
|
Name = sectionValues.TryGetValue("title", out var value) ? value : Name;
|
|
gj.sc(value);
|
|
Info = sectionValues.TryGetValue("description", out var description) ? description : Info;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public sealed partial class ModulePage : Page
|
|
{
|
|
public ModuleViewModel ViewModel
|
|
{
|
|
get; set;
|
|
}
|
|
public ModulePage()
|
|
{
|
|
ViewModel = App.GetService<ModuleViewModel>();
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除模组和文件夹
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private async void Button_Delete(object sender, RoutedEventArgs e)
|
|
{
|
|
var menuItem = sender as Control;
|
|
gj.sc(menuItem);
|
|
if (menuItem != null)
|
|
{
|
|
if (menuItem.DataContext is DataObject folderItem)
|
|
{
|
|
var task = await Dialog.DialogWarnYes("你确定要删除(回收站)" + folderItem.Dri, XamlRoot);
|
|
if (task == ContentDialogResult.Primary)
|
|
{
|
|
if (Directory.Exists(folderItem.Dri))
|
|
{
|
|
// 删除文件夹
|
|
//Directory.Delete(folderItem.Dri, true);
|
|
FileSystem.DeleteDirectory(folderItem.Dri, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
|
|
}
|
|
else if (File.Exists(folderItem.Dri))
|
|
{
|
|
//删除文件
|
|
//File.Delete(folderItem.Dri);
|
|
FileSystem.DeleteFile(folderItem.Dri, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
|
|
}
|
|
}
|
|
ViewModel.ListMod.Remove(folderItem);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 解压模组
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private async void UnzipRwmod(DataObject a)
|
|
{
|
|
ContentDialog dialog = new ContentDialog
|
|
{
|
|
XamlRoot = XamlRoot,
|
|
Title = "提示",
|
|
PrimaryButtonText = "确定",
|
|
SecondaryButtonText = "取消",
|
|
Content = CreateCheckboxContent()
|
|
};
|
|
var contentDialogResult = await dialog.ShowAsync();
|
|
if (contentDialogResult == ContentDialogResult.Primary)
|
|
{
|
|
var checkbox = (dialog.Content as StackPanel)?.Children[1] as CheckBox;
|
|
|
|
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(a.Dri);
|
|
var GetDirectoryName = Path.GetDirectoryName(a.Dri);
|
|
if (Directory.Exists(GetDirectoryName) && fileNameWithoutExtension != null)
|
|
{
|
|
var targetDirectory = Path.Combine(GetDirectoryName, fileNameWithoutExtension);
|
|
var v = wj.UnzipFile(a.Dri, targetDirectory);
|
|
gj.sc("解压成功:" + v);
|
|
if (checkbox?.IsChecked == true)
|
|
{
|
|
File.Delete(a.Dri);
|
|
ViewModel.ListMod.Remove(a);
|
|
}
|
|
if (v)
|
|
{
|
|
ViewModel.ListMod.Remove(new DataObject(new DirectoryInfo(targetDirectory)));
|
|
ViewModel.ListMod.Insert(0, new DataObject(new DirectoryInfo(targetDirectory)));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private FrameworkElement CreateCheckboxContent()
|
|
{
|
|
var checkbox = new CheckBox
|
|
{
|
|
Content = "是否删除源文件",
|
|
IsChecked = false,
|
|
Margin = new Thickness(0, 16, 0, 0),
|
|
|
|
};
|
|
var text = new TextBlock
|
|
{
|
|
Text = "解压模组到目录",
|
|
};
|
|
var stackPanel = new StackPanel();
|
|
stackPanel.Children.Add(text);
|
|
stackPanel.Children.Add(checkbox);
|
|
return stackPanel;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 打包模组
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
public async void Button_Rwmod(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
var menuItem = sender as MenuFlyoutItem;
|
|
if (menuItem != null)
|
|
{
|
|
if (menuItem.DataContext is DataObject folderItem)
|
|
{
|
|
var filepath = Path.Combine(Path.GetDirectoryName(folderItem.Dri), folderItem.Name + ".rwmod");
|
|
if (File.Exists(filepath))
|
|
{
|
|
var show = await new ContentDialog()
|
|
{
|
|
XamlRoot = menuItem.XamlRoot,
|
|
Title = "警告",
|
|
Content = "已经存在必须覆盖",
|
|
PrimaryButtonText = "确定",
|
|
SecondaryButtonText = "取消"
|
|
}.ShowAsync();
|
|
if (show == ContentDialogResult.Primary)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
// 压缩zip
|
|
var v = wj.ZipExample(folderItem.Dri, folderItem.Name + ".rwmod");
|
|
if (v != string.Empty)
|
|
{
|
|
ViewModel.ListMod.Remove(new DataObject(new FileInfo(filepath)));
|
|
ViewModel.ListMod.Insert(0, new DataObject(new FileInfo(v)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 双击GridView事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void BasicGridView_DoubleTapped(object sender, Microsoft.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
|
|
{
|
|
|
|
var gridView = sender as GridView;
|
|
var item = (e.OriginalSource as FrameworkElement)?.DataContext;
|
|
|
|
if (item != null && gridView != null)
|
|
{
|
|
// 这里处理双击事件,例如显示一个消息框
|
|
// 替换为实际的数据类型
|
|
if (item is DataObject clickedItem)
|
|
{
|
|
// 在这里处理双击项
|
|
var IsRwmod = clickedItem.IsRwmod; // 假设你的项有一个 Name 属性
|
|
if (IsRwmod)
|
|
{
|
|
UnzipRwmod(clickedItem);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发布模组
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private async void Button_PostRwmod(object sender, RoutedEventArgs e)
|
|
{
|
|
if (sender is MenuFlyoutItem item)
|
|
{
|
|
if (item.DataContext is not DataObject dataObject)
|
|
{
|
|
return;
|
|
}
|
|
//folderItem.IsRwmod = false;
|
|
var contentDialog = new ContentDialog()
|
|
{
|
|
XamlRoot = XamlRoot,
|
|
Title = "发布",
|
|
};
|
|
var postRwmod = new PostRwmod(contentDialog)
|
|
{
|
|
XamlRoot = XamlRoot
|
|
};
|
|
var h = ((Panel)Content).ActualHeight;
|
|
postRwmod.Height = h - 50;
|
|
contentDialog.Content = postRwmod;
|
|
// 订阅 Closing 事件
|
|
contentDialog.Closing += Dialog.DialogNotEsc;
|
|
|
|
postRwmod.Init(dataObject.Dri);
|
|
await contentDialog.ShowAsync();
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打开目录
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void Button_OpenDir(object sender, RoutedEventArgs e)
|
|
{
|
|
var view = sender as MenuFlyoutItem;
|
|
// 替换为实际的数据类型
|
|
if (view?.DataContext is DataObject clickedItem)
|
|
{
|
|
wj.OpenFileExplorer(clickedItem.Dri);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 打开模组_文件夹
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void Button_OpenMod(object sender, RoutedEventArgs e)
|
|
{
|
|
var view = sender as MenuFlyoutItem;
|
|
// 替换为实际的数据类型
|
|
if (view?.DataContext is DataObject clickedItem)
|
|
{
|
|
if (!clickedItem.IsRwmod)
|
|
{
|
|
new Editor.EditorWin(clickedItem.Dri).Show();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public class MyItemTemplateSelector : DataTemplateSelector
|
|
{
|
|
public DataTemplate Template1
|
|
{
|
|
get; set;
|
|
} = new();
|
|
public DataTemplate Template2
|
|
{
|
|
get; set;
|
|
} = new();
|
|
|
|
protected override DataTemplate SelectTemplateCore(object item)
|
|
{
|
|
if (item is not DataObject dataObject)
|
|
{
|
|
return base.SelectTemplateCore(item);
|
|
}
|
|
if (dataObject.IsRwmod)
|
|
return Template1;
|
|
else
|
|
return Template2;
|
|
}
|
|
} |