mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-04-05 17:37:49 +08:00
修复单元测试失败的问题
This commit is contained in:
parent
43374e02bd
commit
a3081ef4a9
@ -29,23 +29,45 @@ public class ConfigUtils {
|
|||||||
return userDir;
|
return userDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取环境变量,如果找不到则返回默认值
|
||||||
|
@SuppressWarnings("SameParameterValue")
|
||||||
|
private static String env(String key, String def) {
|
||||||
|
String value = System.getenv(key);
|
||||||
|
return value == null ? def : value;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getOfficePluginPath() {
|
// 返回参数列表中第一个真实存在的路径,或者 null
|
||||||
String userDir = System.getenv("KKFILEVIEW_BIN_FOLDER");
|
private static String firstExists(File... paths) {
|
||||||
if (userDir == null) {
|
for (File path : paths) {
|
||||||
userDir = System.getProperty("user.dir");
|
if (path.exists()) {
|
||||||
}
|
return path.getAbsolutePath();
|
||||||
if (userDir.endsWith("bin")) {
|
|
||||||
userDir = userDir.substring(0, userDir.length() - 4);
|
|
||||||
} else {
|
|
||||||
String separator = File.separator;
|
|
||||||
if (!userDir.contains(OFFICE_PLUGIN_NAME)) {
|
|
||||||
userDir = userDir + separator + OFFICE_PLUGIN_NAME;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userDir;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getOfficePluginPath() {
|
||||||
|
String userDir = System.getProperty("user.dir");
|
||||||
|
String binFolder = env("KKFILEVIEW_BIN_FOLDER", userDir);
|
||||||
|
|
||||||
|
File pluginPath = new File(binFolder);
|
||||||
|
|
||||||
|
// 如果指定了 bin 或其父目录,则返回父目录
|
||||||
|
// 否则在当前目录和父目录中寻找 office-plugin
|
||||||
|
if (new File(pluginPath, "bin").exists()) {
|
||||||
|
return pluginPath.getAbsolutePath();
|
||||||
|
|
||||||
|
} else if (pluginPath.exists() && pluginPath.getName().equals("bin")) {
|
||||||
|
return pluginPath.getParentFile().getAbsolutePath();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return firstExists(
|
||||||
|
new File(pluginPath, OFFICE_PLUGIN_NAME),
|
||||||
|
new File(pluginPath.getParentFile(), OFFICE_PLUGIN_NAME)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getCustomizedConfigPath() {
|
public static String getCustomizedConfigPath() {
|
||||||
String homePath = getHomePath();
|
String homePath = getHomePath();
|
||||||
String separator = java.io.File.separator;
|
String separator = java.io.File.separator;
|
||||||
|
Loading…
Reference in New Issue
Block a user