Skip to content

Commit

Permalink
update: 第一次打开的提示,防止文件夹里乱乱的
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxuuu committed Nov 9, 2022
1 parent 124ed48 commit ab50ee0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 21 deletions.
67 changes: 47 additions & 20 deletions llcom/Tools/Global.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using LibUsbDotNet;
using LibUsbDotNet.Main;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand All @@ -13,6 +12,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Shapes;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace llcom.Tools
Expand Down Expand Up @@ -45,16 +45,39 @@ public static bool isMainWindowsClosed
public static Model.Settings setting;
public static Model.Uart uart = new Model.Uart();

//软件文件名
private static string _fileName = "";
public static string FileName
{
get
{
if (String.IsNullOrWhiteSpace(_fileName))
{
using (var processModule = Process.GetCurrentProcess().MainModule)
{
_fileName = System.IO.Path.GetFileName(processModule?.FileName);
}
}
return _fileName;
}
}

//软件根目录
private static string _appPath = null;
/// <summary>
/// 软件根目录(末尾带\)
/// </summary>
public static string AppPath
{
get
{
if(_appPath == null)
{
_appPath = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName);
if(!_appPath.EndsWith("\\"))
using (var processModule = Process.GetCurrentProcess().MainModule)
{
_appPath = System.IO.Path.GetDirectoryName(processModule?.FileName);
}
if (!_appPath.EndsWith("\\"))
_appPath = _appPath + "\\";
}
return _appPath;
Expand All @@ -65,25 +88,12 @@ public static string AppPath
public static string ProfilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\llcom\";

/// <summary>
/// 获取实际的ProfilePath路径(商店软件里用
/// 获取实际的ProfilePath路径(目前没啥用了
/// </summary>
/// <returns></returns>
public static string GetTrueProfilePath()
{
if(IsMSIX())
{
//C:\Program Files\WindowsApps\800948F61A16.llcom_1.0.44.0_x86__bd8bdx79914mr\llcom\
string pkgPath = AppPath.Substring(0,AppPath.LastIndexOf(@"\llcom\"));
pkgPath = pkgPath.Substring(pkgPath.LastIndexOf("\\") + 1);
pkgPath = pkgPath.Substring(0, pkgPath.IndexOf("_")) + pkgPath.Substring(pkgPath.LastIndexOf("_"));
//C:\Users\chenx\AppData\Local\Packages\800948F61A16.llcom_bd8bdx79914mr\LocalCache\Local\llcom
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
@"\Packages\" + pkgPath + @"\LocalCache\Local\llcom\";
}
else
{
return ProfilePath;
}
return ProfilePath;
}

/// <summary>
Expand Down Expand Up @@ -153,6 +163,15 @@ public static void LoadSetting()
}
else
{
if(Directory.GetFiles(ProfilePath).Length > 10)
{
var r = Tools.InputDialog.OpenDialog("检测到当前文件夹有其他文件\r\n" +
"建议新建一个文件夹给llcom,并将llcom.exe放入其中\r\n" +
"不然当前文件夹会显得很乱哦~\r\n" +
"是否想要继续运行呢?",null,"温馨提示");
if(!r.Item1)
Environment.Exit(1);
}
setting = new Model.Settings();
}
}
Expand Down Expand Up @@ -184,8 +203,16 @@ public static void Initial()
$"建议升级到最新.net framework版本");
ReportBug = false;
}
//文件名不能改!
if(FileName.ToUpper() != "LLCOM.EXE")
{
MessageBox.Show("啊呀呀,软件文件名被改了。。。\r\n" +
"为了保证软件功能的正常运行,请将exe名改回llcom.exe");
Environment.Exit(1);
}
//C:\Users\chenx\AppData\Local\Temp\7zO05433053\user_script_run
if (AppPath.ToUpper().Contains(@"\APPDATA\LOCAL\TEMP\"))
if (AppPath.ToUpper().Contains(@"\APPDATA\LOCAL\TEMP\") ||
AppPath.ToUpper().Contains(@"\WINDOWS\TEMP\"))
{
System.Windows.MessageBox.Show("请勿在压缩包内直接打开本软件。");
Environment.Exit(1);
Expand Down
8 changes: 7 additions & 1 deletion llcom/View/InputDialogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public InputDialogWindow(string prompt, string defaultInput = "", string title =
{
InitializeComponent();
this.DataContext = this;
this.Value = defaultInput;
if (defaultInput == null)
InputText.Visibility = Visibility.Collapsed;
else
{
this.Value = defaultInput;
InputText.Visibility = Visibility.Visible;
}
this.Title = title ?? TryFindResource("InputDialogTitle") as string ?? "?!";
PromptLabel.Text = prompt;
}
Expand Down

0 comments on commit ab50ee0

Please sign in to comment.