修复旧版本升级兼容性问题

This commit is contained in:
makejava 2022-10-13 11:58:55 +08:00
parent 79c401d1f4
commit fc843d0ee6
1 changed files with 24 additions and 2 deletions

View File

@ -1,14 +1,17 @@
package com.sjhy.plugin.service; package com.sjhy.plugin.service;
import com.intellij.database.psi.DbTable; import com.intellij.database.psi.DbTable;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass; import com.intellij.psi.PsiClass;
import com.sjhy.plugin.dto.TableInfoSettingsDTO; import com.sjhy.plugin.dto.TableInfoSettingsDTO;
import com.sjhy.plugin.entity.TableInfo; import com.sjhy.plugin.entity.TableInfo;
import com.sjhy.plugin.service.impl.TableInfoSettingsServiceImpl; import com.sjhy.plugin.service.impl.TableInfoSettingsServiceImpl;
import com.sjhy.plugin.tool.ProjectUtils; import com.sjhy.plugin.tool.ProjectUtils;
import java.io.IOException;
/** /**
* @author makejava * @author makejava
* @version 1.0.0 * @version 1.0.0
@ -21,7 +24,26 @@ public interface TableInfoSettingsService extends PersistentStateComponent<Table
* @return {@link SettingsStorageService} * @return {@link SettingsStorageService}
*/ */
static TableInfoSettingsService getInstance() { static TableInfoSettingsService getInstance() {
return ServiceManager.getService(ProjectUtils.getCurrProject(), TableInfoSettingsServiceImpl.class); try {
return ProjectUtils.getCurrProject().getService(TableInfoSettingsServiceImpl.class);
} catch (AssertionError e) {
// 出现配置文件被错误修改或不兼容时直接删除配置文件
VirtualFile workspaceFile = ProjectUtils.getCurrProject().getWorkspaceFile();
if (workspaceFile != null) {
VirtualFile configFile = workspaceFile.getParent().findChild("easyCodeTableSetting.xml");
if (configFile != null && configFile.exists()) {
WriteCommandAction.runWriteCommandAction(ProjectUtils.getCurrProject(), () -> {
try {
configFile.delete(null);
} catch (IOException ex) {
ex.printStackTrace();
}
});
}
}
// 重新获取配置
return ProjectUtils.getCurrProject().getService(TableInfoSettingsServiceImpl.class);
}
} }
/** /**