update to v1.0.20 优化了错误检查提醒机制,帮助用户更好地排查设置错误

This commit is contained in:
kohgylw 2019-08-08 10:43:05 +08:00
parent 9a633ad72b
commit 2c5cdcd5b4
23 changed files with 297 additions and 105 deletions

View File

@ -117,7 +117,30 @@ public class ConsoleRunner {
} else if (ConsoleRunner.ctl.start()) {
Printer.instance.print("kiftd服务器已启动可以正常访问了您可以使用 -status 指令查看运行状态。");
} else {
Printer.instance.print("错误kiftd服务器未能启动请重试或检查设置。");
if (ConfigureReader.instance().getPropertiesStatus() != 0) {
switch (ConfigureReader.instance().getPropertiesStatus()) {
case ConfigureReader.INVALID_PORT:
Printer.instance.print("错误kiftd服务器未能启动端口设置无效。");
break;
case ConfigureReader.INVALID_BUFFER_SIZE:
Printer.instance.print("错误kiftd服务器未能启动缓存设置无效。");
break;
case ConfigureReader.INVALID_FILE_SYSTEM_PATH:
Printer.instance.print("错误kiftd服务器未能启动文件系统路径或某一扩展存储区设置无效。");
break;
case ConfigureReader.INVALID_LOG:
Printer.instance.print("错误kiftd服务器未能启动日志设置无效。");
break;
case ConfigureReader.INVALID_VC:
Printer.instance.print("错误kiftd服务器未能启动登录验证码设置无效。");
break;
default:
Printer.instance.print("错误kiftd服务器未能启动请重试或检查设置。");
break;
}
} else {
Printer.instance.print("错误kiftd服务器未能启动请重试或检查设置。");
}
}
}

View File

@ -45,9 +45,9 @@ public class UIRunner {
}
@Override
public boolean getPropertiesStatus() {
public int getPropertiesStatus() {
// TODO 自动生成的方法存根
return ConfigureReader.instance().getPropertiesStatus() == ConfigureReader.LEGAL_PROPERTIES;
return ConfigureReader.instance().getPropertiesStatus();
}
@Override
@ -98,6 +98,37 @@ public class UIRunner {
}
return fsps;
}
@Override
public LogLevel getInitLogLevel() {
// TODO 自动生成的方法存根
return ConfigureReader.instance().getInitLogLevel();
}
@Override
public VCLevel getInitVCLevel() {
// TODO 自动生成的方法存根
return ConfigureReader.instance().getInitVCLevel();
}
@Override
public String getInitFileSystemPath() {
// TODO 自动生成的方法存根
return ConfigureReader.instance().getInitFileSystemPath();
}
@Override
public String getInitProt() {
// TODO 自动生成的方法存根
return ConfigureReader.instance().getInitPort();
}
@Override
public String getInitBufferSize() {
// TODO 自动生成的方法存根
return ConfigureReader.instance().getInitBuffSize();
}
});
ServerUIModule.setUpdateSetting(new UpdateSetting() {
@ -108,12 +139,6 @@ public class UIRunner {
}
});
ui.show();
final Thread t = new Thread(() -> {
if (ConfigureReader.instance().getPropertiesStatus() == ConfigureReader.LEGAL_PROPERTIES) {
ui.updateServerStatus();
}
});
t.start();
}
/**

View File

@ -210,6 +210,14 @@ public class ConfigureReader {
return this.bufferSize;
}
public String getInitBuffSize() {
if (this.serverp != null && serverp.getProperty("buff.size") != null) {
return serverp.getProperty("buff.size");
} else {
return DEFAULT_BUFFER_SIZE + "";
}
}
public boolean inspectLogLevel(final LogLevel l) {
int o = 0;
int m = 0;
@ -266,18 +274,30 @@ public class ConfigureReader {
return this.fileSystemPath;
}
public String getInitFileSystemPath() {
if (this.serverp != null && serverp.getProperty("FS.path") != null) {
return serverp.getProperty("FS.path").equals("DEFAULT") ? DEFAULT_FILE_SYSTEM_PATH
: serverp.getProperty("FS.path");
} else {
return DEFAULT_FILE_SYSTEM_PATH;
}
}
public String getFileBlockPath() {
return this.fileBlockPath;
}
/**
*
* <h2>获取全部扩展存储区</h2>
* <p>得到全部扩展存储区列表以便进行文件块的存取操作</p>
* <p>
* 得到全部扩展存储区列表以便进行文件块的存取操作
* </p>
*
* @author 青阳龙野(kohgylw)
* @return java.util.List<kohgylw.kiftd.server.pojo.ExtendStores> 所有扩展存储区对象的列表
*/
public List<ExtendStores> getExtendStores(){
public List<ExtendStores> getExtendStores() {
return extendStores;
}
@ -314,6 +334,26 @@ public class ConfigureReader {
}
}
public LogLevel getInitLogLevel() {
if (serverp != null && serverp.getProperty("log") != null) {
switch (serverp.getProperty("log")) {
case "N": {
return LogLevel.None;
}
case "R": {
return LogLevel.Runtime_Exception;
}
case "E": {
return LogLevel.Event;
}
default:
return LogLevel.Event;
}
} else {
return LogLevel.Event;
}
}
/**
*
* <h2>获得验证码等级</h2>
@ -345,10 +385,35 @@ public class ConfigureReader {
}
}
public VCLevel getInitVCLevel() {
if (serverp != null && serverp.getProperty("VC.level") != null) {
switch (serverp.getProperty("VC.level")) {
case "STANDARD":
return VCLevel.Standard;
case "SIMP":
return VCLevel.Simplified;
case "CLOSE":
return VCLevel.Close;
default:
return VCLevel.Standard;
}
} else {
return VCLevel.Standard;
}
}
public int getPort() {
return this.port;
}
public String getInitPort() {
if (this.serverp != null && serverp.getProperty("port") != null) {
return serverp.getProperty("port");
} else {
return DEFAULT_PORT + "";
}
}
public int getPropertiesStatus() {
return this.propertiesStatus;
}
@ -356,7 +421,6 @@ public class ConfigureReader {
public boolean doUpdate(final ServerSetting ss) {
if (ss != null) {
Printer.instance.print("正在更新服务器配置...");
this.serverp.clear();
this.serverp.setProperty("mustLogin", ss.isMustLogin() ? "N" : "O");
this.serverp.setProperty("buff.size", ss.getBuffSize() + "");
String loglevelCode = "E";
@ -393,8 +457,11 @@ public class ConfigureReader {
this.serverp.setProperty("FS.path",
(ss.getFsPath() + File.separator).equals(this.DEFAULT_FILE_SYSTEM_PATH) ? "DEFAULT"
: ss.getFsPath());
for(ExtendStores es:ss.getExtendStores()) {
this.serverp.setProperty("FS.extend."+es.getIndex(), es.getPath().getAbsolutePath());
for (short i = 1; i < 32; i++) {
this.serverp.remove("FS.extend." + i);// 清空旧的扩展存储区设置
}
for (ExtendStores es : ss.getExtendStores()) {
this.serverp.setProperty("FS.extend." + es.getIndex(), es.getPath().getAbsolutePath());
}
if (this.testServerPropertiesAndEffect() == 0) {
try {
@ -496,10 +563,11 @@ public class ConfigureReader {
if (!fileSystemPath.endsWith(File.separator)) {
fileSystemPath = fileSystemPath + File.separator;
}
for(short i=1;i<32;i++) {
if(serverp.getProperty("FS.extend."+i)!=null) {
ExtendStores es=new ExtendStores();
es.setPath(new File(serverp.getProperty("FS.extend."+i)));
extendStores.clear();
for (short i = 1; i < 32; i++) {
if (serverp.getProperty("FS.extend." + i) != null) {
ExtendStores es = new ExtendStores();
es.setPath(new File(serverp.getProperty("FS.extend." + i)));
es.setIndex(i);
extendStores.add(es);
}
@ -509,16 +577,17 @@ public class ConfigureReader {
Printer.instance.print("错误:文件系统路径[" + this.fileSystemPath + "]无效,该路径必须指向一个具备读写权限的文件夹。");
return 3;
}
for(ExtendStores es:extendStores) {
if(!es.getPath().isDirectory() || !es.getPath().canRead() || !es.getPath().canWrite()) {
for (ExtendStores es : extendStores) {
if (!es.getPath().isDirectory() || !es.getPath().canRead() || !es.getPath().canWrite()) {
Printer.instance.print("错误:扩展存储区路径[" + es.getPath().getAbsolutePath() + "]无效,该路径必须指向一个具备读写权限的文件夹。");
return 3;
}
}
for(int i=0;i<extendStores.size()-1;i++) {
for(int j=i+1;j<extendStores.size();j++) {
if(extendStores.get(i).getPath().equals(extendStores.get(j).getPath())) {
Printer.instance.print("错误:扩展存储区路径[" + extendStores.get(j).getPath().getAbsolutePath() + "]无效,该路径已被其他扩展存储区占用。");
for (int i = 0; i < extendStores.size() - 1; i++) {
for (int j = i + 1; j < extendStores.size(); j++) {
if (extendStores.get(i).getPath().equals(extendStores.get(j).getPath())) {
Printer.instance.print(
"错误:扩展存储区路径[" + extendStores.get(j).getPath().getAbsolutePath() + "]无效,该路径已被其他扩展存储区占用。");
return 3;
}
}
@ -541,8 +610,7 @@ public class ConfigureReader {
Printer.instance.print("错误:无法创建临时文件存放区[" + this.TFPath + "]。");
return 7;
}
if ("true".equals(serverp.getProperty("mysql.enable"))) {
dbDriver = "com.mysql.cj.jdbc.Driver";
String url = serverp.getProperty("mysql.url", "127.0.0.1/kift");
@ -929,5 +997,4 @@ public class ConfigureReader {
}
return r;
}
}

View File

@ -7,20 +7,30 @@ import kohgylw.kiftd.ui.pojo.FileSystemPath;
public interface GetServerStatus
{
boolean getPropertiesStatus();
int getPropertiesStatus();
boolean getServerStatus();
int getPort();
String getInitProt();
int getBufferSize();
String getInitBufferSize();
LogLevel getLogLevel();
LogLevel getInitLogLevel();
VCLevel getVCLevel();
VCLevel getInitVCLevel();
String getFileSystemPath();
String getInitFileSystemPath();
boolean getMustLogin();
List<FileSystemPath> getExtendStores();

View File

@ -12,6 +12,7 @@ import java.text.*;
import java.util.*;
import kohgylw.kiftd.printer.Printer;
import kohgylw.kiftd.server.util.ConfigureReader;
import kohgylw.kiftd.ui.callback.*;
public class ServerUIModule extends KiftdDynamicWindow {
@ -68,49 +69,48 @@ public class ServerUIModule extends KiftdDynamicWindow {
if (SystemTray.isSupported()) {
ServerUIModule.window.setDefaultCloseOperation(1);
ServerUIModule.tray = SystemTray.getSystemTray();
String iconType="/kohgylw/kiftd/ui/resource/icon_tray.png";
if(System.getProperty("os.name").toLowerCase().indexOf("window")>=0) {
iconType="/kohgylw/kiftd/ui/resource/icon_tray_w.png";
String iconType = "/kohgylw/kiftd/ui/resource/icon_tray.png";
if (System.getProperty("os.name").toLowerCase().indexOf("window") >= 0) {
iconType = "/kohgylw/kiftd/ui/resource/icon_tray_w.png";
}
try {
(ServerUIModule.trayIcon = new TrayIcon(
ImageIO.read(this.getClass().getResourceAsStream(iconType))))
.setToolTip("青阳网络文件系统-kiftd");
(ServerUIModule.trayIcon = new TrayIcon(ImageIO.read(this.getClass().getResourceAsStream(iconType))))
.setToolTip("青阳网络文件系统-kiftd");
trayIcon.setImageAutoSize(true);
final PopupMenu pMenu = new PopupMenu();
final MenuItem exit = new MenuItem("退出(Exit)");
filesViewer = new MenuItem("文件...(Files)");
final MenuItem show = new MenuItem("显示主窗口(Show)");
trayIcon.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mousePressed(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mouseExited(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO 自动生成的方法存根
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO 自动生成的方法存根
if(e.getClickCount()==2) {
if (e.getClickCount() == 2) {
show();
}
}
@ -276,7 +276,30 @@ public class ServerUIModule extends KiftdDynamicWindow {
printMessage("KIFT服务器未能成功启动请检查设置或查看异常信息。");
}
} else {
printMessage("KIFT无法启动请检查设置。");
if(ConfigureReader.instance().getPropertiesStatus() != 0) {
switch (ConfigureReader.instance().getPropertiesStatus()) {
case ConfigureReader.INVALID_PORT:
printMessage("KIFT无法启动端口设置无效。");
break;
case ConfigureReader.INVALID_BUFFER_SIZE:
printMessage("KIFT无法启动缓存设置无效。");
break;
case ConfigureReader.INVALID_FILE_SYSTEM_PATH:
printMessage("KIFT无法启动文件系统路径或某一扩展存储区设置无效。");
break;
case ConfigureReader.INVALID_LOG:
printMessage("KIFT无法启动日志设置无效。");
break;
case ConfigureReader.INVALID_VC:
printMessage("KIFT无法启动登录验证码设置无效。");
break;
default:
printMessage("KIFT无法启动请检查设置或查看异常信息。");
break;
}
}else {
printMessage("KIFT无法启动请检查设置或查看异常信息。");
}
serverStatusLab.setText(S_STOP);
}
updateServerStatus();
@ -381,6 +404,7 @@ public class ServerUIModule extends KiftdDynamicWindow {
public void show() {
ServerUIModule.window.setVisible(true);
updateServerStatus();
}
public static void setOnCloseServer(final OnCloseServer cs) {
@ -404,8 +428,8 @@ public class ServerUIModule extends KiftdDynamicWindow {
}
public void updateServerStatus() {
final Thread t = new Thread(() -> {
if (ServerUIModule.st != null) {
if (ServerUIModule.st != null) {
Thread t = new Thread(() -> {
if (ServerUIModule.st.getServerStatus()) {
ServerUIModule.serverStatusLab.setText(S_START);
ServerUIModule.start.setEnabled(false);
@ -422,29 +446,30 @@ public class ServerUIModule extends KiftdDynamicWindow {
fileIOUtil.setEnabled(true);
filesViewer.setEnabled(true);
ServerUIModule.portStatusLab.setText(ServerUIModule.st.getPort() + "");
switch (st.getLogLevel()) {
case Event: {
ServerUIModule.logLevelLab.setText(L_ALL);
break;
}
case None: {
ServerUIModule.logLevelLab.setText(L_NONE);
break;
}
case Runtime_Exception: {
ServerUIModule.logLevelLab.setText(L_EXCEPTION);
break;
}
default: {
ServerUIModule.logLevelLab.setText("无法获取(?)");
break;
}
if (ServerUIModule.st.getLogLevel() != null) {
switch (ServerUIModule.st.getLogLevel()) {
case Event: {
ServerUIModule.logLevelLab.setText(L_ALL);
break;
}
case None: {
ServerUIModule.logLevelLab.setText(L_NONE);
break;
}
case Runtime_Exception: {
ServerUIModule.logLevelLab.setText(L_EXCEPTION);
break;
}
default: {
ServerUIModule.logLevelLab.setText("无法获取(?)");
break;
}
}
}
ServerUIModule.bufferSizeLab.setText(ServerUIModule.st.getBufferSize() / 1024 + " KB");
}
return;
});
t.start();
});
t.start();
}
}
private void exit() {

View File

@ -162,9 +162,9 @@ public class SettingWindow extends KiftdDynamicWindow {
if (chooserPath.isDirectory()) {
ss.setFsPath(chooserPath.getAbsolutePath());
}
List<ExtendStores> ess=new ArrayList<>();
for(FileSystemPath fsp:extendStores) {
ExtendStores es=new ExtendStores();
List<ExtendStores> ess = new ArrayList<>();
for (FileSystemPath fsp : extendStores) {
ExtendStores es = new ExtendStores();
es.setIndex(fsp.getIndex());
es.setPath(fsp.getPath());
ess.add(es);
@ -200,11 +200,11 @@ public class SettingWindow extends KiftdDynamicWindow {
ss.setVc(VCLevel.Standard);
break;
}
case 1:{
case 1: {
ss.setVc(VCLevel.Simplified);
break;
}
case 2:{
case 2: {
ss.setVc(VCLevel.Close);
break;
}
@ -216,6 +216,7 @@ public class SettingWindow extends KiftdDynamicWindow {
window.setVisible(false);
}
} catch (Exception exc) {
exc.printStackTrace();
Printer.instance.print("错误:无法应用设置");
}
} else {
@ -230,7 +231,7 @@ public class SettingWindow extends KiftdDynamicWindow {
@Override
public void actionPerformed(ActionEvent e) {
fspv=FileSystemPathViewer.getInstance();
fspv = FileSystemPathViewer.getInstance();
fspv.show();
}
});
@ -245,42 +246,83 @@ public class SettingWindow extends KiftdDynamicWindow {
private void getServerStatus() {
final Thread t = new Thread(() -> {
if (SettingWindow.st != null) {
SettingWindow.bufferinput.setText(SettingWindow.st.getBufferSize() / 1024 + "");
SettingWindow.portinput.setText(SettingWindow.st.getPort() + "");
chooserPath = new File(SettingWindow.st.getFileSystemPath());
SettingWindow.bufferinput
.setText(SettingWindow.st.getBufferSize() == 0 ? SettingWindow.st.getInitBufferSize()
: SettingWindow.st.getBufferSize() / 1024 + "");
SettingWindow.portinput.setText(SettingWindow.st.getPort() == 0 ? SettingWindow.st.getInitProt() + ""
: SettingWindow.st.getPort() + "");
if (SettingWindow.st.getFileSystemPath() != null) {
chooserPath = new File(SettingWindow.st.getFileSystemPath());
} else {
chooserPath = new File(SettingWindow.st.getInitFileSystemPath());
}
extendStores = SettingWindow.st.getExtendStores();
switch (st.getLogLevel()) {
case Event: {
SettingWindow.logLevelinput.setSelectedIndex(0);
break;
}
case Runtime_Exception: {
SettingWindow.logLevelinput.setSelectedIndex(1);
break;
}
case None: {
SettingWindow.logLevelinput.setSelectedIndex(2);
break;
}
if (st.getLogLevel() != null) {
switch (st.getLogLevel()) {
case Event: {
SettingWindow.logLevelinput.setSelectedIndex(0);
break;
}
case Runtime_Exception: {
SettingWindow.logLevelinput.setSelectedIndex(1);
break;
}
case None: {
SettingWindow.logLevelinput.setSelectedIndex(2);
break;
}
}
} else {
switch (st.getInitLogLevel()) {
case Event: {
SettingWindow.logLevelinput.setSelectedIndex(0);
break;
}
case Runtime_Exception: {
SettingWindow.logLevelinput.setSelectedIndex(1);
break;
}
case None: {
SettingWindow.logLevelinput.setSelectedIndex(2);
break;
}
}
}
if (SettingWindow.st.getMustLogin()) {
SettingWindow.mlinput.setSelectedIndex(0);
} else {
SettingWindow.mlinput.setSelectedIndex(1);
}
switch (SettingWindow.st.getVCLevel()) {
case Standard: {
SettingWindow.vcinput.setSelectedIndex(0);
break;
}
case Simplified: {
SettingWindow.vcinput.setSelectedIndex(1);
break;
}
case Close: {
SettingWindow.vcinput.setSelectedIndex(2);
break;
}
if (SettingWindow.st.getVCLevel() != null) {
switch (SettingWindow.st.getVCLevel()) {
case Standard: {
SettingWindow.vcinput.setSelectedIndex(0);
break;
}
case Simplified: {
SettingWindow.vcinput.setSelectedIndex(1);
break;
}
case Close: {
SettingWindow.vcinput.setSelectedIndex(2);
break;
}
}
} else {
switch (SettingWindow.st.getInitVCLevel()) {
case Standard: {
SettingWindow.vcinput.setSelectedIndex(0);
break;
}
case Simplified: {
SettingWindow.vcinput.setSelectedIndex(1);
break;
}
case Close: {
SettingWindow.vcinput.setSelectedIndex(2);
break;
}
}
}
}
return;

View File

@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Tue Aug 06 15:03:52 CST 2019
#Thu Aug 08 10:42:32 CST 2019
version=1.0.20-SNAPSHOT
groupId=kohgylw
m2e.projectName=kiftd