2025-12-03 16:08:14 +08:00
|
|
|
"use strict";
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
|
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
|
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
|
|
|
}
|
|
|
|
|
Object.defineProperty(o, k2, desc);
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.StorageService = void 0;
|
|
|
|
|
// src/panels/services/StorageService.ts
|
|
|
|
|
const vscode = __importStar(require("vscode"));
|
|
|
|
|
const fs = __importStar(require("fs"));
|
|
|
|
|
const path = __importStar(require("path"));
|
|
|
|
|
/**
|
|
|
|
|
* 数据存储服务
|
|
|
|
|
* 负责项目的持久化存储和加载
|
|
|
|
|
*/
|
|
|
|
|
class StorageService {
|
|
|
|
|
/**
|
|
|
|
|
* 加载项目数据
|
|
|
|
|
*/
|
|
|
|
|
static async loadProjectData(projectPath) {
|
|
|
|
|
try {
|
2026-01-30 11:06:42 +08:00
|
|
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), 'dcsp-data.json');
|
2025-12-03 16:08:14 +08:00
|
|
|
try {
|
|
|
|
|
await vscode.workspace.fs.stat(dataUri);
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
console.warn('未找到项目数据文件');
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
const fileData = await vscode.workspace.fs.readFile(dataUri);
|
|
|
|
|
const dataStr = new TextDecoder().decode(fileData);
|
|
|
|
|
const data = JSON.parse(dataStr);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
console.error('加载项目数据失败:', error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 保存项目数据
|
|
|
|
|
*/
|
|
|
|
|
static async saveProjectData(projectPath, data) {
|
|
|
|
|
try {
|
2026-01-30 11:06:42 +08:00
|
|
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), 'dcsp-data.json');
|
2025-12-03 16:08:14 +08:00
|
|
|
const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2));
|
|
|
|
|
await vscode.workspace.fs.writeFile(dataUri, uint8Array);
|
|
|
|
|
console.log('✅ 项目数据已保存');
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
console.error('保存项目数据失败:', error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 检查项目路径是否有数据
|
|
|
|
|
*/
|
|
|
|
|
static async checkProjectPathHasData(projectPath) {
|
|
|
|
|
try {
|
2026-01-30 11:06:42 +08:00
|
|
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), 'dcsp-data.json');
|
2025-12-03 16:08:14 +08:00
|
|
|
await vscode.workspace.fs.stat(dataUri);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 加载仓库配置
|
|
|
|
|
*/
|
|
|
|
|
static async loadRepoConfigs(extensionUri) {
|
|
|
|
|
try {
|
|
|
|
|
const configPath = path.join(extensionUri.fsPath, 'dcsp-repos.json');
|
|
|
|
|
if (!fs.existsSync(configPath)) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
const content = await fs.promises.readFile(configPath, 'utf8');
|
|
|
|
|
if (!content.trim()) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
const parsed = JSON.parse(content);
|
|
|
|
|
if (Array.isArray(parsed)) {
|
|
|
|
|
return parsed;
|
|
|
|
|
}
|
|
|
|
|
else if (parsed && Array.isArray(parsed.repos)) {
|
|
|
|
|
return parsed.repos;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
console.error('加载仓库配置失败:', error);
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 确保仓库配置文件存在
|
|
|
|
|
*/
|
|
|
|
|
static async ensureRepoConfigFileExists(extensionUri) {
|
|
|
|
|
const configPath = path.join(extensionUri.fsPath, 'dcsp-repos.json');
|
|
|
|
|
if (!fs.existsSync(configPath)) {
|
|
|
|
|
const defaultContent = JSON.stringify({
|
|
|
|
|
repos: [
|
|
|
|
|
{
|
|
|
|
|
name: 'example-repo',
|
|
|
|
|
url: 'https://github.com/username/repo.git',
|
|
|
|
|
username: '',
|
|
|
|
|
token: ''
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}, null, 2);
|
|
|
|
|
await fs.promises.writeFile(configPath, defaultContent, 'utf8');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 打开仓库配置文件
|
|
|
|
|
*/
|
|
|
|
|
static async openRepoConfig(extensionUri) {
|
|
|
|
|
try {
|
|
|
|
|
await StorageService.ensureRepoConfigFileExists(extensionUri);
|
|
|
|
|
const configPath = path.join(extensionUri.fsPath, 'dcsp-repos.json');
|
|
|
|
|
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(configPath));
|
|
|
|
|
await vscode.window.showTextDocument(doc);
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
vscode.window.showErrorMessage(`打开仓库配置文件失败: ${error}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.StorageService = StorageService;
|
|
|
|
|
//# sourceMappingURL=StorageService.js.map
|