From 1d0454ccf9551559f1bdaa747c5abcc295a24808 Mon Sep 17 00:00:00 2001
From: zsyg <3872006562@qq.com>
Date: Tue, 1 Jul 2025 20:10:29 +0800
Subject: [PATCH] Add files via upload
---
AppStore.csproj | 7 +
MainForm.cs | 2910 ++++++++++++++++++++++++-----------------------
2 files changed, 1482 insertions(+), 1435 deletions(-)
diff --git a/AppStore.csproj b/AppStore.csproj
index aa4d5db..0ff88fd 100644
--- a/AppStore.csproj
+++ b/AppStore.csproj
@@ -16,6 +16,9 @@
+
+ PreserveNewest
+
PreserveNewest
@@ -33,4 +36,8 @@
+
+
+
+
diff --git a/MainForm.cs b/MainForm.cs
index e9a7708..1cd8d0a 100644
--- a/MainForm.cs
+++ b/MainForm.cs
@@ -1,1435 +1,1475 @@
-#nullable enable
-using System;
-using System.Drawing;
-using System.Windows.Forms;
-using System.IO;
-using System.Security.Cryptography;
-using System.Text;
-using System.Text.Json;
-using System.Diagnostics;
-using AppStore;
-
-namespace AppStore
-{
- ///
- /// 主窗体类,负责应用程序的主界面显示和交互
- ///
- public class MainForm : Form
- {
- private static readonly string CacheDir = Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
- "zsyg", "kortapp-z", ".cache");
-
- private class AppPositionCache
- {
- public string AppName { get; set; } = string.Empty;
- public int X { get; set; }
- public int Y { get; set; }
- public DateTime LastUpdated { get; set; } = DateTime.Now;
- }
-
- private static string GetPositionCacheFilePath(string appName)
- {
- using var md5 = MD5.Create();
- var hash = md5.ComputeHash(Encoding.UTF8.GetBytes(appName));
- var fileName = BitConverter.ToString(hash).Replace("-", "").ToLower() + ".json";
- return Path.Combine(CacheDir, fileName);
- }
-
- private static void EnsureCacheDirectory()
- {
- try
- {
- if (!Directory.Exists(CacheDir))
- {
- Directory.CreateDirectory(CacheDir);
- Logger.Log($"已创建缓存目录: {CacheDir}");
- }
- }
- catch (Exception ex)
- {
- Logger.LogError($"创建缓存目录失败: {CacheDir}", ex);
- throw;
- }
- }
-
- private static bool TryReadPositionCache(string appName, out AppPositionCache? cacheData)
- {
- cacheData = null;
- var cacheFile = GetPositionCacheFilePath(appName);
-
- if (!File.Exists(cacheFile))
- return false;
-
- try
- {
- var json = File.ReadAllText(cacheFile);
- cacheData = JsonSerializer.Deserialize(json);
- return cacheData != null;
- }
- catch
- {
- return false;
- }
- }
-
- private static void WritePositionCache(string appName, Point position)
- {
- try
- {
- EnsureCacheDirectory();
- var cacheFile = GetPositionCacheFilePath(appName);
-
- var cacheData = new AppPositionCache
- {
- AppName = appName,
- X = position.X,
- Y = position.Y,
- LastUpdated = DateTime.Now
- };
-
- var json = JsonSerializer.Serialize(cacheData);
- File.WriteAllText(cacheFile, json);
- Logger.Log($"已保存位置缓存: {appName} ({position.X}, {position.Y})");
- }
- catch (Exception ex)
- {
- Logger.LogError($"保存位置缓存失败: {appName}", ex);
- throw;
- }
- }
-
- private static bool IsPositionCacheValid(AppPositionCache cacheData)
- {
- // 缓存有效期设为7天
- return (DateTime.Now - cacheData.LastUpdated).TotalDays <= 7;
- }
-
- private static void SaveAllCardPositions(FlowLayoutPanel flowPanel)
- {
- foreach (Control control in flowPanel.Controls)
- {
- if (control is AppCard card)
- {
- WritePositionCache(card.AppName, control.Location);
- }
- }
- }
-
- // 软件下载按钮
- private Button btnApps = null!;
- // 下载进度按钮
- private Button btnDownloads = null!;
- // 设置按钮
- private Button btnSettings = null!;
- // 关于按钮
- private Button btnAbout = null!;
- // 内容显示面板
- private Panel contentPanel = null!;
-
- ///
- /// 初始化窗体组件
- ///
- private void InitializeComponent()
- {
- // 设置窗体基本属性
- // 窗体基本设置
- this.Text = "kortapp-z";
- this.Size = new Size(1430, 1050); // 增加窗体高度
- this.MinimumSize = new Size(600, 600); // 设置最小尺寸
- this.StartPosition = FormStartPosition.CenterScreen;
- this.Icon = new Icon("img/ico/icon.ico"); // 设置窗体图标
-
- // 注册主题变更事件
- ThemeManager.ThemeChanged += (theme) =>
- {
- this.Invoke((MethodInvoker)delegate {
- AnimateThemeChange();
- });
- };
-
- // 现代化顶部导航栏
- Panel buttonPanel = new Panel();
- buttonPanel.Dock = DockStyle.Top;
- buttonPanel.Height = 70;
- buttonPanel.BackColor = ThemeManager.ControlBackgroundColor;
- buttonPanel.Padding = new Padding(10, 15, 10, 0);
- buttonPanel.AutoScroll = true;
- buttonPanel.AutoSize = true;
- buttonPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
-
- // 导航按钮样式
- Action