Skip to content

Commit

Permalink
Improve startup speed
Browse files Browse the repository at this point in the history
  • Loading branch information
hbl917070 committed Mar 15, 2024
1 parent f300d38 commit fffd45f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Website:<a href="https://hbl917070.github.io/aeropic/en/">hbl917070.github.io/
- There is no functional difference between the Store and Portable versions
- The Store version can be updated through the store and will not leave any data after Tiefsee is deleted
- The Portable version requires the installation of [.NET Desktop Runtime 7 (x64)](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) to run
- The Portable version can use 'portable mode' by creating a `portableMode` folder next to Tiefsee.exe, and all data will be stored inside
- The Portable version can use 'portable mode' by creating a `PortableMode` folder next to Tiefsee.exe, and all data will be stored inside

> If there are no special requirements, it is recommended to use the Store version
Expand Down
2 changes: 1 addition & 1 deletion README.zh_TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Tiefsee
- 商店版與免安裝版功能上沒有差異
- 商店版可以透過商店來進行更新,且刪除 Tiefsee 後不會留下任何資料
- 免安裝版需要安裝 [.NET Desktop Runtime 7 (x64)](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) 才能運行
- 免安裝版可以使用「便攜模式」 ,在 Tiefsee.exe 旁邊新建一個`portableMode`資料夾,資料就都會儲存在裡面
- 免安裝版可以使用「便攜模式」 ,在 Tiefsee.exe 旁邊新建一個`PortableMode`資料夾,資料就都會儲存在裡面

> 沒有特別需求的話,我推薦使用商店版
Expand Down
72 changes: 58 additions & 14 deletions Tiefsee/AppPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,58 @@ public class AppPath {
/// <summary> 工作列右下角的圖示 </summary>
public static string logoIcon = "";

public static void Init() {

try { // 商店版
appData = Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path;
appData = Path.Combine(appData, "Local", "Tiefsee");
StartWindow.isStoreApp = true;
/// <summary>
/// 在使用 Init() 之前如果就需要使用 appData 的話,就使用此方法
/// </summary>
public static void InitAppData() {
if (appData != null) { return; }

// 便攜模式 (如果存在此資料夾,就把資料儲存在這裡
string portableMode = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PortableMode");
if (Directory.Exists(portableMode)) {
appData = portableMode;
StartWindow.isPortableMode = true;
}
else {
appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Tiefsee");
StartWindow.isPortableMode = false;
}
catch { // 傳統應用程式版
appDataStartIni = Path.Combine(appData, "Start.ini");
}

public static void Init(string iniAppData, bool iniIsStoreApp) {

string portableMode = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "portableMode");
if (Directory.Exists(portableMode)) { // 便攜模式 (如果存在此資料夾,就把資料儲存在這裡
appData = portableMode;
InitAppData();

// 需要更新 ini
bool needUpdateIni = false;

// 便攜模式
if (StartWindow.isPortableMode) {
StartWindow.isStoreApp = false;
}
// 不存在此路徑,表示是傳統應用程式版
else if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../TiefseeLauncher/Tiefsee.exe")) == false) {
StartWindow.isStoreApp = false;
}
// 如果已經 ini 檔案有資料,就使用 ini 檔案的資料
else if (iniAppData != "") {
StartWindow.isStoreApp = iniIsStoreApp;
appData = iniAppData;
}
else {
try {
// 商店版
appData = Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path;
appData = Path.Combine(appData, "Local", "Tiefsee");
StartWindow.isStoreApp = true;
needUpdateIni = true;
}
else {
catch {
// 傳統應用程式版
appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Tiefsee");
StartWindow.isStoreApp = false;
}

StartWindow.isStoreApp = false;
}

appDataLock = Path.Combine(appData, "Lock");
Expand All @@ -76,13 +110,23 @@ public static void Init() {
//------

// 如果資料夾不存在,就新建

if (Directory.Exists(appData) == false) {
Directory.CreateDirectory(appData);
}
if (Directory.Exists(appDataPlugin) == false) {
Directory.CreateDirectory(appDataPlugin);
}

if (needUpdateIni) {
// 重新讀取 ini
var iniManager = new IniManager(AppPath.appDataStartIni);
Program.startPort = Int32.Parse(iniManager.ReadIniFile("setting", "startPort", "4876"));
Program.startType = Int32.Parse(iniManager.ReadIniFile("setting", "startType", "3"));
// 把資料寫入 ini 檔案,下次就可以直接讀取
iniManager.WriteIniFile("temporary", "appData", appData);
iniManager.WriteIniFile("temporary", "isStoreApp", StartWindow.isStoreApp.ToString());
}

}

}
16 changes: 10 additions & 6 deletions Tiefsee/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ static class Program {
static void Main(string[] args) {

// 修改 工作目錄 為程式資料夾 (如果有傳入 args 的話,工作目錄會被修改,所以需要改回來
Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
AppPath.Init();
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
AppPath.InitAppData();

var iniManager = new IniManager(AppPath.appDataStartIni);
startPort = Int32.Parse(iniManager.ReadIniFile("setting", "startPort", "4876"));
startType = Int32.Parse(iniManager.ReadIniFile("setting", "startType", "3"));
var appData = iniManager.ReadIniFile("temporary", "appData", "");
var isStoreApp = iniManager.ReadIniFile("temporary", "isStoreApp", "") == "True";

AppPath.Init(appData, isStoreApp);

// 如果是商店 APP 版,且是來自「開機自動啟動」
if (StartWindow.isStoreApp) {
Expand All @@ -42,10 +50,6 @@ static void Main(string[] args) {
catch { }
}

IniManager iniManager = new IniManager(AppPath.appDataStartIni);
startPort = Int32.Parse(iniManager.ReadIniFile("setting", "startPort", "4876"));
startType = Int32.Parse(iniManager.ReadIniFile("setting", "startType", "3"));

bool argsIsNone = (args.Length == 1 && args[0] == "none"); // 啟動參數是 none

if (args.Length >= 1 && args[0] == "restart") { // 啟動參數是 restart
Expand Down
2 changes: 2 additions & 0 deletions Tiefsee/StartWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class StartWindow : Form {
public static bool isRunGC = false;
/// <summary> 是否為商店版 APP </summary>
public static bool isStoreApp = false;
/// <summary> 是否為 便攜模式 </summary>
public static bool isPortableMode = false;
/// <summary> 用於鎖定 port 檔案 </summary>
private FileStream fsPort;
/// <summary> 是否為 win11 </summary>
Expand Down
16 changes: 8 additions & 8 deletions TiefseeLauncherDll/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace TiefseeLauncher;

public class Program {

/*[STAThread]
/*
[STAThread]
public static void Main(string[] args) {
new Launcher().Init(args);
}*/
} */

// 導出到 C++
[UnmanagedCallersOnly(EntryPoint = "run")]
Expand Down Expand Up @@ -56,7 +56,7 @@ public void Init(string[] args) {
exePath = Path.Combine(baseDirectory, "../Tiefsee/TiefseeCore.exe");
}

string portableMode = Path.Combine(baseDirectory, "portableMode");
string portableMode = Path.Combine(baseDirectory, "PortableMode");
if (Directory.Exists(portableMode)) { // 便攜模式 (如果存在此資料夾,就把資料儲存在這裡
appData = portableMode;
}
Expand All @@ -66,7 +66,6 @@ public void Init(string[] args) {

appDataStartIni = Path.Combine(appData, "Start.ini");
appDataPort = Path.Combine(appData, "Port");

var iniManager = new IniManager(appDataStartIni);
startType = Int32.Parse(iniManager.ReadIniFile("setting", "startType", "3"));

Expand Down Expand Up @@ -174,8 +173,9 @@ public string ReadIniFile(string section, string key, string defaultValue) {
return lpReturnedString.ToString();
}

/*
// write ini data depend on section and key
// public void WriteIniFile(string section, string key, Object value) {
// WritePrivateProfileString(section, key, value.ToString(), filePath);
// }
public void WriteIniFile(string section, string key, Object value) {
WritePrivateProfileString(section, key, value.ToString(), filePath);
}*/
}

0 comments on commit fffd45f

Please sign in to comment.