"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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SquirrelFileSystemProvider = void 0;
const vscode = __importStar(require("vscode"));
class SquirrelFileSystemProvider {
    constructor(model) {
        this._onDidChangeFile = new vscode.EventEmitter();
        this.onDidChangeFile = this._onDidChangeFile.event;
        this.model = model;
    }
    // 读取文件
    async readFile(uri) {
        const filePath = this.getPathFromUri(uri);
        const content = await this.model.getFileContent(filePath);
        if (content === undefined) {
            throw vscode.FileSystemError.FileNotFound(uri);
        }
        return new TextEncoder().encode(content);
    }
    // 写入文件
    async writeFile(uri, content, options) {
        const filePath = this.getPathFromUri(uri);
        const textContent = new TextDecoder().decode(content);
        const success = await this.model.saveFileContent(filePath, textContent);
        if (!success) {
            throw vscode.FileSystemError.Unavailable('保存文件失败');
        }
    }
    // 其他必须实现的方法（简化实现）
    stat(uri) {
        return {
            type: vscode.FileType.File,
            ctime: Date.now(),
            mtime: Date.now(),
            size: 0
        };
    }
    readDirectory(uri) {
        return [];
    }
    createDirectory(uri) {
        throw vscode.FileSystemError.NoPermissions('不支持创建目录');
    }
    delete(uri) {
        throw vscode.FileSystemError.NoPermissions('不支持删除文件');
    }
    rename(oldUri, newUri, options) {
        throw vscode.FileSystemError.NoPermissions('不支持重命名文件');
    }
    watch(uri, options) {
        return new vscode.Disposable(() => { });
    }
    // 从 URI 解析文件路径
    getPathFromUri(uri) {
        if (uri.scheme !== 'squirrel') {
            throw vscode.FileSystemError.FileNotFound(uri);
        }
        return uri.path.substring(1); // 去掉开头的 '/'
    }
}
exports.SquirrelFileSystemProvider = SquirrelFileSystemProvider;
//# sourceMappingURL=fileSystemProvider.js.map