Skip to content

Commit

Permalink
Remove serverCache variable and related code
Browse files Browse the repository at this point in the history
  • Loading branch information
hbl917070 committed Mar 13, 2024
1 parent eec7913 commit f300d38
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 43 deletions.
4 changes: 0 additions & 4 deletions Tiefsee/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ static class Program {
public static int startPort;
/// <summary> 1=直接啟動 2=快速啟動 3=快速啟動且常駐 4=單一執行個體 5=單一執行個體且常駐 </summary>
public static int startType;
/// <summary> 伺服器對靜態資源快取的時間(秒) </summary>
public static int serverCache;
/// <summary> 本地伺服器 </summary>
public static WebServer webServer;
/// <summary> 起始視窗,關閉此視窗就會結束程式 </summary>
Expand Down Expand Up @@ -47,7 +45,6 @@ static void Main(string[] args) {
IniManager iniManager = new IniManager(AppPath.appDataStartIni);
startPort = Int32.Parse(iniManager.ReadIniFile("setting", "startPort", "4876"));
startType = Int32.Parse(iniManager.ReadIniFile("setting", "startType", "3"));
serverCache = Int32.Parse(iniManager.ReadIniFile("setting", "serverCache", "0"));

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

Expand Down Expand Up @@ -79,7 +76,6 @@ static void Main(string[] args) {
System.Windows.Forms.MessageBox.Show("Tiefsee localhost server error");
return;
}
webServer.controller.SetCacheTime(serverCache);

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Expand Down
12 changes: 0 additions & 12 deletions Tiefsee/Server/WebServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Tiefsee;
public class WebServerController {

private WebServer webServer;
private int cacheTime = 0; // 靜態資源快取的時間

public WebServerController(WebServer ws) {

Expand Down Expand Up @@ -657,7 +656,6 @@ private bool HeadersAdd304(RequestData d, string path) {

d.context.Response.Headers.Add("Last-Modified", lastModified); // 檔案建立的時間
d.context.Response.Headers.Add("ETag", etag); // 瀏覽器用來判斷資源是否有更新的key
d.context.Response.Headers.Add("Cache-Control", "public, max-age=" + cacheTime); // 讓瀏覽器快取檔案

if (d.context.Request.Headers["If-None-Match"] == etag) { // 表示瀏覽器還留有暫存,狀態304後,不用回傳任何資料
d.context.Response.StatusCode = 304;
Expand All @@ -667,16 +665,6 @@ private bool HeadersAdd304(RequestData d, string path) {
return false;
}

/// <summary>
/// 設定是否對靜態資源使用快取
/// </summary>
/// <param name="time"> 秒數 </param>
public void SetCacheTime(int time) {
if (time <= 0) { time = 0; }
if (time >= 31536000) { time = 31536000; } // 一年
cacheTime = time;
}

/// <summary>
/// 回傳字串
/// </summary>
Expand Down
7 changes: 1 addition & 6 deletions Tiefsee/VW/WV_Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,12 @@ public void ClearBrowserCache() {
/// </summary>
/// <param name="startPort">程式開始的port</param>
/// <param name="startType">1=直接啟動 2=快速啟動 3=快速啟動+常駐 4=單一個體 5=單一個體+常駐</param>
/// <param name="serverCache"> 伺服器對靜態資源使用快取 0=不使用 1=使用 </param>
public void SetStartIni(int startPort, int startType, int serverCache) {
public void SetStartIni(int startPort, int startType) {
IniManager iniManager = new IniManager(AppPath.appDataStartIni);
iniManager.WriteIniFile("setting", "startPort", startPort);
iniManager.WriteIniFile("setting", "startType", startType);
iniManager.WriteIniFile("setting", "serverCache", serverCache);
Program.startPort = startPort;
Program.startType = startType;
Program.serverCache = serverCache;

Program.webServer.controller.SetCacheTime(serverCache);
}

/// <summary>
Expand Down
3 changes: 0 additions & 3 deletions Tiefsee/WebWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public static string GetAppInfo(string[] args, int quickLookRunType) {
args = args,
startType = Program.startType,
startPort = Program.startPort,
serverCache = Program.serverCache,
appDirPath = System.AppDomain.CurrentDomain.BaseDirectory,
appDataPath = AppPath.appData,
mainPort = Program.webServer.port,
Expand Down Expand Up @@ -239,8 +238,6 @@ public class AppInfo {
public int startType { get; set; }
/// <summary> 程式開始的port </summary>
public int startPort { get; set; }
/// <summary> 伺服器對靜態資源使用快取 0=不使用 1=使用 </summary>
public int serverCache { get; set; }
/// <summary> 程式所在的資料夾 </summary>
public string appDirPath { get; set; }
/// <summary> 程式的暫存資料夾 </summary>
Expand Down
6 changes: 0 additions & 6 deletions Www/ejs/SettingWindow/SettingWindow.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -889,14 +889,8 @@
<div class="text-content">
<input class="text-input" type="number" id="text-startPort">
</div>

<div class="text-title" style="display:none;"> 快取有效時間 (秒) </div>
<div class="text-content" style="display:none;">
<input class="text-input" type="number" id="text-serverCache">
</div>
</div>


<div class="box">
<div class="box-title" i18n="sw.reset.resetSettings"> 重設設定 </div>

Expand Down
9 changes: 1 addition & 8 deletions Www/ts/SettingWindow/SettingWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1088,12 +1088,10 @@ class SettingWindow {
addLoadEvent(() => {

var text_startPort = getDom("#text-startPort") as HTMLInputElement;
var text_serverCache = getDom("#text-serverCache") as HTMLInputElement;
var btn_restart = getDom("#btn-startupMode-restart") as HTMLButtonElement;

Lib.setRadio("[name='radio-startType']", appInfo.startType.toString())
text_startPort.value = appInfo.startPort.toString();
text_serverCache.value = appInfo.serverCache.toString();

// 調整選項後,顯示「重新啟動」的按鈕
btn_restart.style.display = "none";
Expand All @@ -1114,7 +1112,6 @@ class SettingWindow {
// 儲存 start.ini
let startPort = parseInt(text_startPort.value);
let startType: any = Lib.getRadio("[name='radio-startType']");
let serverCache = parseInt(text_serverCache.value);

if (isNaN(startPort)) { startPort = 4876; }
if (startPort > 65535) { startPort = 65535; }
Expand All @@ -1123,11 +1120,7 @@ class SettingWindow {
if (startType.search(/^[1|2|3|4|5]$/) !== 0) { startType = 2; }
startType = parseInt(startType);

if (isNaN(serverCache)) { serverCache = 0; }
if (serverCache > 31536000) { serverCache = 31536000; }
if (serverCache < 0) { serverCache = 0; }

await WV_Window.SetStartIni(startPort, startType, serverCache);
await WV_Window.SetStartIni(startPort, startType);
});

// 重新啟動Tiefsee
Expand Down
5 changes: 1 addition & 4 deletions Www/ts/d/NetAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface WV_Window {
ClearBrowserCache(): void;

/** 儲存到 start.ini */
SetStartIni(startPort: number, startType: number, serverCache: number)
SetStartIni(startPort: number, startType: number)

/** 取得 AppInfo*/
GetAppInfo(): string;
Expand Down Expand Up @@ -541,9 +541,6 @@ interface AppInfo {
/** 程式開始的port */
startPort: number;

/** 伺服器對靜態資源快取的時間(秒) */
serverCache: number;

/** 程式所在的資料夾 */
appDirPath: string;

Expand Down

0 comments on commit f300d38

Please sign in to comment.