diff --git a/CHANGELOG.md b/CHANGELOG.md index 7395bb1..29b41e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,20 @@ # Change Log +## [0.11.6] - 14/09/2023 + +### Added + +- `Transfer File` explorer command. +- Default '*.' ignore case. +- System name to most logs. + +### Fixed + +- Deleting files wouldn't clear the cache. + ## [0.11.5] - 04/08/2023 + ### Changed - Refresh login doesn't try after 3 failed attempts. diff --git a/package.json b/package.json index c2c54ec..e5a22ef 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "homepage": "https://github.com/TaBayramNTT/vscode-miisync", "icon": "resources/icon.png", - "version": "0.11.5", + "version": "0.11.6", "license": "MIT", "engines": { "vscode": "^1.77.0" @@ -84,6 +84,12 @@ "category": "mii", "enablement": "miisync.enabled && miisync.loggedin" }, + { + "command": "miisync.transferfile", + "title": "Transfer File", + "category": "zmii", + "enablement": "miisync.enabled && miisync.loggedin" + }, { "command": "miisync.deletefile", "title": "Delete Current File", @@ -267,6 +273,11 @@ "group": "miisync.file@3", "when": "miisync.enabled && !explorerResourceIsRoot && !explorerResourceIsFolder" }, + { + "command": "miisync.transferfile", + "group": "miisync.file@4", + "when": "miisync.enabled && !explorerResourceIsRoot && !explorerResourceIsFolder" + }, { "command": "miisync.deletefile", "group": "miisync.file@5", diff --git a/src/commands/commandgitchanges.ts b/src/commands/commandgitchanges.ts index 36d6324..ae068cf 100644 --- a/src/commands/commandgitchanges.ts +++ b/src/commands/commandgitchanges.ts @@ -24,17 +24,17 @@ export async function OnCommandUploadGitChanges() { const files = changes.filter((change) => (change.status != Status.DELETED && change?.uri)).map(change => change.uri); statusBar.updateBar('Uploading', Icon.spinLoading, { duration: -1 }); - logger.infos("Upload Git Changes", "Changes:" + files.length + " Started"); + logger.infoplus(configManager.CurrentSystem.name,"Upload Git Changes", "Changes:" + files.length + " Started"); //todo: try to prevent possible duplicate bug const response = await UploadFilesLimited(files, userConfig, configManager.CurrentSystem); if(response.aborted){ statusBar.updateBar('Cancelled', Icon.success, { duration: 1 }); - logger.infos("Upload Git Changes", "Cancelled"); + logger.infoplus(configManager.CurrentSystem.name,"Upload Git Changes", "Cancelled"); } else{ statusBar.updateBar('Uploaded', Icon.success, { duration: 1 }); - logger.infos("Upload Git Changes", "Completed"); + logger.infoplus(configManager.CurrentSystem.name,"Upload Git Changes", "Completed"); } } \ No newline at end of file diff --git a/src/commands/commandtransferfile.ts b/src/commands/commandtransferfile.ts new file mode 100644 index 0000000..4918b28 --- /dev/null +++ b/src/commands/commandtransferfile.ts @@ -0,0 +1,14 @@ +import { Uri } from "vscode"; +import { configManager } from "../modules/config"; +import { TransferFile } from "../transfer/transfer"; + + +export async function OnCommandTransferFile(uri: Uri) { + const userConfig = await configManager.load(); + if (!userConfig) return; + + if (uri) { + TransferFile(uri, userConfig); + return; + } +} \ No newline at end of file diff --git a/src/events/changeactivettexteditor.ts b/src/events/changeactivettexteditor.ts index 72f86e3..8729e1b 100644 --- a/src/events/changeactivettexteditor.ts +++ b/src/events/changeactivettexteditor.ts @@ -56,7 +56,7 @@ async function CheckFileDifference(document: vscode.TextDocument, fileProp: File if (response === 1) { await writeFile(document.fileName, Buffer.from(payload.Value, 'base64'), { encoding: "utf8" }); statusBar.updateBar("Downloaded " + path.basename(document.fileName), Icon.success, { duration: 3 }); - logger.infos('Download File', path.basename(document.fileName) + ": Finished."); + logger.infoplus(system.name,'Download File', path.basename(document.fileName) + ": Finished."); } else if (response === 2) { const extension = path.extname(document.fileName).substring(1); diff --git a/src/extension/activation.ts b/src/extension/activation.ts index d55a743..29b06d4 100644 --- a/src/extension/activation.ts +++ b/src/extension/activation.ts @@ -13,6 +13,7 @@ import { OnCommandOpenRootConfig } from '../commands/commandopenrootconfig'; import { OnCommandOpenScreen } from '../commands/commandopenscreen'; import { OnCommandLogin, OnCommandLogout, OnCommandSwitchSystem } from '../commands/commandsession'; import { OnCommandDisableDownloadOnOpen, OnCommandDisableSyncSave, OnCommandEnableDownloadOnOpen, OnCommandEnableSyncSave } from '../commands/commandtogglesync'; +import { OnCommandTransferFile } from '../commands/commandtransferfile'; import { OnCommandTransferFolder } from '../commands/commandtransferfolder'; import { OnCommandUploadFile } from '../commands/commanduploadfile'; import { OnCommandUploadFolder } from '../commands/commanduploadfolder'; @@ -50,6 +51,7 @@ export function RegisterCommands(context: vscode.ExtensionContext) { RegisterCommand('miisync.downloadfileproperties', OnCommandDownloadFileProperties, context); RegisterCommand('miisync.uploadfolder', OnCommandUploadFolder, context); RegisterCommand('miisync.transferfolder', OnCommandTransferFolder, context); + RegisterCommand('miisync.transferfile', OnCommandTransferFile, context); RegisterCommand('miisync.disabledownloadonopen', OnCommandDisableDownloadOnOpen, context); RegisterCommand('miisync.enabledownloadonopen', OnCommandEnableDownloadOnOpen, context); RegisterCommand('miisync.deletefile', OnCommandDeleteFile, context); diff --git a/src/miiservice/blowoutservice.ts b/src/miiservice/blowoutservice.ts new file mode 100644 index 0000000..fafae49 --- /dev/null +++ b/src/miiservice/blowoutservice.ts @@ -0,0 +1,26 @@ +import { Request, Service } from './abstract/miiservice.js'; +import { MII, RowsetsMessage } from './abstract/responsetypes.js'; + +class BlowoutService extends Service { + name: string = "Delete Batch"; + mode: string = "XMII/Catalog?Mode=Blowout&Class=Content&Content-Type=text/xml"; + + async call({ host, port }: Request, folderPath: string) { + const url = this.get(host, port, folderPath); + const { value, error, isError } = await this.fetch(new URL(url)); + let data: MII = null; + if (!isError) { + data = this.parseXML(value); + } + return data; + } + get(host: string, port: number, sourcePath: string) { + return this.generateURL(host, port, "http") + `&${this.generateParams(sourcePath)}&__=${new Date().getTime()}`; + } + protected generateParams(folder: string) { + return "Folder=" + folder; + } +} + + +export const blowoutService = new BlowoutService(); \ No newline at end of file diff --git a/src/modules/config.ts b/src/modules/config.ts index 3e53a98..9f1181a 100644 --- a/src/modules/config.ts +++ b/src/modules/config.ts @@ -60,7 +60,7 @@ function GetWorkspaceConfig(): UserConfig { remotePath: conf.get("remotePath", 'MES'), downloadOnOpen: false, uploadOnSave: false, - ignore: conf.get('ignore', ['package.json']), + ignore: conf.get('ignore', ['package.json', '.*']), include: conf.get('include', []), useRootConfig: conf.get('useRootConfig', false), rootConfig: conf.get('rootConfig', '') diff --git a/src/transfer/download.ts b/src/transfer/download.ts index b4bbd72..4d7ea8f 100644 --- a/src/transfer/download.ts +++ b/src/transfer/download.ts @@ -36,7 +36,7 @@ export async function DownloadFile(uri: Uri, userConfig: UserConfig, system: Sys await writeFile(filePath, Buffer.from(payload.Value, 'base64'), { encoding: "utf8" }) statusBar.updateBar("Downloaded " + fileName, Icon.success, { duration: 3 }); - logger.infos('Download File', fileName + ": Finished."); + logger.infoplus(system.name,'Download File', fileName + ": Finished."); } @@ -46,7 +46,7 @@ export async function DownloadFolder(folderUri: Uri | string, userConfig: UserCo return false; } statusBar.updateBar('Downloading', Icon.spinLoading, { duration: -1 }); - logger.infos("Download Folder", path.basename(folderPath) + ": Started"); + logger.infoplus(system.name,"Download Folder", path.basename(folderPath) + ": Started"); function getPath(item: File | Folder) { if ('FolderName' in item) { @@ -65,11 +65,11 @@ export async function DownloadFolder(folderUri: Uri | string, userConfig: UserCo if(response.aborted){ statusBar.updateBar('Cancelled', Icon.success, { duration: 1 }); - logger.infos("Download Folder", path.basename(folderPath) + ": Cancelled"); + logger.infoplus(system.name,"Download Folder", path.basename(folderPath) + ": Cancelled"); } else{ statusBar.updateBar('Downloaded', Icon.success, { duration: 1 }); - logger.infos("Download Folder", path.basename(folderPath) + ": Completed"); + logger.infoplus(system.name,"Download Folder", path.basename(folderPath) + ": Completed"); } } @@ -97,7 +97,7 @@ export async function DownloadRemoteFolder(remoteFolderPath: string, userConfig: const folderName = path.basename(remoteFolderPath); statusBar.updateBar('Downloading', Icon.spinLoading, { duration: -1 }); - logger.infos("Download Remote Folder", folderName + ": Started"); + logger.infoplus(system.name,"Download Remote Folder", folderName + ": Started"); const workspaceFolder = GetCurrentWorkspaceFolder().fsPath; function getPath(item: File | Folder) { @@ -116,11 +116,11 @@ export async function DownloadRemoteFolder(remoteFolderPath: string, userConfig: if(response.aborted){ statusBar.updateBar('Cancelled', Icon.success, { duration: 1 }); - logger.infos("Download Remote Folder", folderName + ": Cancelled"); + logger.infoplus(system.name,"Download Remote Folder", folderName + ": Cancelled"); } else{ statusBar.updateBar('Downloaded', Icon.success, { duration: 1 }); - logger.infos("Download Remote Folder", folderName + ": Completed"); + logger.infoplus(system.name,"Download Remote Folder", folderName + ": Completed"); } @@ -145,7 +145,7 @@ export async function DownloadRemoteFile({ filePath, name }: { filePath: string, } statusBar.updateBar('Downloaded', Icon.success, { duration: 1 }); - logger.infos('Download Remote File', name + ": Finished."); + logger.infoplus(system.name,'Download Remote File', name + ": Finished."); } export async function DownloadContextDirectory(userConfig: UserConfig, system: System) { @@ -156,12 +156,12 @@ export async function DownloadContextDirectory(userConfig: UserConfig, system: S const parentPath = path.dirname(sourcePath).replaceAll(path.sep, "/"); statusBar.updateBar('Downloading', Icon.spinLoading, { duration: -1 }); - logger.infos("Download Context Directory", sourcePath + ": Started"); + logger.infoplus(system.name,"Download Context Directory", sourcePath + ": Started"); const files = await loadFilesInsideService.call({ host: system.host, port: system.port }, sourcePath); remoteDirectoryTree.generateItemsByFiles(files?.Rowsets?.Rowset?.Row); statusBar.updateBar('Downloaded', Icon.success, { duration: 2 }); - logger.infos("Download Context Directory", sourcePath + ": Completed"); + logger.infoplus(system.name,"Download Context Directory", sourcePath + ": Completed"); } //--------------------------------------------------------------- diff --git a/src/transfer/request.ts b/src/transfer/request.ts index 9ce284f..764486e 100644 --- a/src/transfer/request.ts +++ b/src/transfer/request.ts @@ -2,6 +2,7 @@ import { Uri } from "vscode"; import { System } from "../extension/system"; +import { blowoutService } from "../miiservice/blowoutservice"; import { deleteBatchService } from "../miiservice/deletebatchservice"; import { readFilePropertiesService } from "../miiservice/readfilepropertiesservice"; import { UserConfig } from "../modules/config"; @@ -33,7 +34,8 @@ export async function DeleteFile(uri: Uri, userConfig: UserConfig, system: Syste const response = await deleteBatchService.call({ host: system.host, port: system.port }, sourcePath); if (response) { const fileName = path.basename(sourcePath); - logger.infos("Delete File", fileName + ": " + response?.Rowsets?.Messages?.Message); + logger.infoplus(system.name,"Delete File", fileName + ": " + response?.Rowsets?.Messages?.Message); + await blowoutService.call({host: system.host, port: system.port}, sourcePath); } statusBar.updateBar('Deleted', Icon.success, { duration: 1 }) @@ -56,7 +58,8 @@ export async function DeleteFolder(uri: Uri, userConfig: UserConfig, system: Sys const response = await deleteBatchService.call({ host: system.host, port: system.port }, sourcePath); if (response) { const folderName = path.basename(sourcePath); - logger.infos("Delete Folder", folderName + ": " + response?.Rowsets?.Messages?.Message); + logger.infoplus(system.name,"Delete Folder", folderName + ": " + response?.Rowsets?.Messages?.Message); + await blowoutService.call({host: system.host, port: system.port}, sourcePath); } statusBar.updateBar('Deleted', Icon.success, { duration: 1 }) diff --git a/src/transfer/transfer.ts b/src/transfer/transfer.ts index b3bbff8..48f5519 100644 --- a/src/transfer/transfer.ts +++ b/src/transfer/transfer.ts @@ -1,3 +1,4 @@ +import { readFile } from "fs-extra"; import { Uri } from "vscode"; import { System } from "../extension/system"; import { UserConfig, configManager } from "../modules/config"; @@ -7,6 +8,7 @@ import { QuickPickItem } from "../ui/quickpick"; import statusBar, { Icon } from "../ui/statusbar"; import { GetUserManager } from "../user/usermanager"; import { UploadFolderLimited } from "./limited/upload"; +import { UploadFile } from "./upload"; import path = require("path"); @@ -25,18 +27,38 @@ export async function TransferFolder(uri: Uri, userConfig: UserConfig) { if (!await user.login()) return; statusBar.updateBar('Transfering', Icon.spinLoading, { duration: -1 }); - logger.infos("Transfer Folder", path.basename(uri.fsPath) + ": Started"); + logger.infoplus(configManager.CurrentSystem.name, "Transfer Folder", "->" + system.name + ', ' + path.basename(uri.fsPath) + ": Started"); const response = await UploadFolderLimited(uri.fsPath, userConfig, system); if (response.aborted) { statusBar.updateBar('Cancelled', Icon.success, { duration: 1 }); - logger.infos("Transfer Folder", path.basename(uri.fsPath) + ": Cancelled"); + logger.infoplus(configManager.CurrentSystem.name, "Transfer Folder", "->" + system.name + ', ' + path.basename(uri.fsPath) + ": Cancelled"); } else { statusBar.updateBar('Transferred', Icon.success, { duration: 1 }); - logger.infos("Transfer Folder", path.basename(uri.fsPath) + ": Completed"); + logger.infoplus(configManager.CurrentSystem.name, "Transfer Folder", "->" + system.name + ', ' + path.basename(uri.fsPath) + ": Completed"); } } +} + +export async function TransferFile(uri: Uri, userConfig: UserConfig) { + let picks: QuickPickItem[] = []; + for (const system of userConfig.systems) { + if (configManager.CurrentSystem != system) { + picks.push({ label: system.name, description: system.host + ':' + system.port, object: system }) + } + } + + const quickResponse: QuickPickItem = await ShowQuickPick(picks, { title: 'Pick System' }); + if (quickResponse) { + const system = quickResponse.object; + const user = GetUserManager(system, true); + if (!await user.login()) return; + + const content = (await readFile(uri.fsPath)).toString('utf-8'); + const response = await UploadFile(uri, content, userConfig, system); + } + } \ No newline at end of file diff --git a/src/transfer/upload.ts b/src/transfer/upload.ts index 588e4a6..e8341f1 100644 --- a/src/transfer/upload.ts +++ b/src/transfer/upload.ts @@ -26,7 +26,7 @@ export async function UploadFile(uri: Uri, content: string, userConfig: UserConf statusBar.updateBar('Uploading', Icon.spinLoading, { duration: -1 }); const response = await saveFileService.call({ host: system.host, port: system.port, body: "Content=" + base64Content }, sourcePath); if (response) { - logger.infos("Upload File", fileName + ": " + response?.Rowsets?.Messages?.Message); + logger.infoplus(system.name,"Upload File", fileName + ": " + response?.Rowsets?.Messages?.Message); } statusBar.updateBar("Uploaded " + fileName, Icon.success, { duration: 3 }); } @@ -49,17 +49,17 @@ export async function UploadFolder(folderUri: Uri | string, userConfig: UserConf return; } statusBar.updateBar('Uploading', Icon.spinLoading, { duration: -1 }); - logger.infos("Upload Folder", folderName + ": Started"); + logger.infoplus(system.name,"Upload Folder", folderName + ": Started"); const response = await UploadFolderLimited(folderPath, userConfig, system); if (response.aborted) { statusBar.updateBar('Cancelled', Icon.success, { duration: 1 }); - logger.infos("Upload Folder", folderName + ": Cancelled"); + logger.infoplus(system.name,"Upload Folder", folderName + ": Cancelled"); } else { statusBar.updateBar('Uploaded', Icon.success, { duration: 1 }); - logger.infos("Upload Folder", folderName + ": Completed"); + logger.infoplus(system.name,"Upload Folder", folderName + ": Completed"); } diff --git a/src/ui/logger.ts b/src/ui/logger.ts index b1964cc..b008d18 100644 --- a/src/ui/logger.ts +++ b/src/ui/logger.ts @@ -32,8 +32,8 @@ export class Logger implements ILogger { this.log('[fail]', message, ...args); } - infos(source: string, message: string, ...args: any[]) { - this.log('[info]', "(" + source + ")", message, ...args); + infoplus(systemName: string, source: string, message: string, ...args: any[]) { + this.log('[info]','<'+systemName+'>', "(" + source + ")", message, ...args); } toastError(message: string | Error, ...args: any[]) {