From a28e3576968d0b2a302c219c33501a76f7676e88 Mon Sep 17 00:00:00 2001 From: chinonso098 Date: Thu, 8 Aug 2024 15:13:05 -0400 Subject: [PATCH] copy from folder to desktop using cntxt menu works --- .../system-component/menu/menu.component.ts | 23 ++- .../shared/system-component/menu/menu.item.ts | 6 +- src/app/shared/system-service/file.service.ts | 130 ++++++++++++++++- .../shared/system-service/menu.services.ts | 20 ++- .../system-apps/desktop/desktop.component.ts | 79 ++++++---- .../fileexplorer/fileexplorer.component.ts | 94 +++++++++++- .../filemanager/filemanager.component.ts | 12 +- .../system-apps/terminal/terminal.commands.ts | 136 +----------------- src/osdrive/Games/D3D.url | 2 +- src/osdrive/Games/Diggers.url | 2 +- src/osdrive/Games/Doom.url | 2 +- 11 files changed, 309 insertions(+), 197 deletions(-) diff --git a/src/app/shared/system-component/menu/menu.component.ts b/src/app/shared/system-component/menu/menu.component.ts index 1663f59f..5e83dcf8 100644 --- a/src/app/shared/system-component/menu/menu.component.ts +++ b/src/app/shared/system-component/menu/menu.component.ts @@ -1,5 +1,5 @@ import { Component, Input, OnChanges, SimpleChanges, OnDestroy } from '@angular/core'; -import {DesktopMenu, GeneralMenu } from './menu.item'; +import {NestedMenu, GeneralMenu } from './menu.item'; import { MenuService } from '../../system-service/menu.services'; import { Subscription } from 'rxjs'; @@ -11,33 +11,32 @@ import { Subscription } from 'rxjs'; export class MenuComponent implements OnChanges, OnDestroy{ @Input() generalMenu: GeneralMenu[] = []; - @Input() desktopMenu: DesktopMenu[] = []; + @Input() desktopMenu: NestedMenu[] = []; @Input() menuType = ''; private _menuService:MenuService; private _storeDataSub!:Subscription; + isPasteActive!:boolean; menuOption = ''; fileExplrMngrMenuOption = "file-explorer-file-manager-menu"; tskBarMenuOption = "taskbar-menu"; deskTopMenuOption = "desktop-menu"; keys: string[] = []; - data = 'NOPATH'; paste = 'Paste'; - actions:string[]=[]; - - isPasteActive!:boolean; constructor(menuService:MenuService) { this._menuService = menuService; this.isPasteActive = this._menuService.getPasteState(); this._storeDataSub = this._menuService.storeData.subscribe(p => { - this.data = p[0]; - p.shift(); - this.actions = [...p] - this._menuService.setPasteState(this.activatePaste()); + const path = p[0]; + const actions = p[1]; + + this._menuService.setPath(path); + this._menuService.setActions(actions); + this._menuService.setPasteState(true); }) } @@ -57,8 +56,4 @@ export class MenuComponent implements OnChanges, OnDestroy{ this.keys = Object.keys(obj); } - activatePaste():boolean{ - return (this.data === 'NOPATH')? false: true; - } - } diff --git a/src/app/shared/system-component/menu/menu.item.ts b/src/app/shared/system-component/menu/menu.item.ts index 36d22602..cc293587 100644 --- a/src/app/shared/system-component/menu/menu.item.ts +++ b/src/app/shared/system-component/menu/menu.item.ts @@ -4,16 +4,16 @@ export interface GeneralMenu { action: () => void; } -export interface DesktopMenu{ +export interface NestedMenu{ icon1: string; icon2: string; label: string; - nest: DesktopMenuItem[]; + nest: NestedMenuItem[]; action: () => void; emptyline: boolean; } -export interface DesktopMenuItem { +export interface NestedMenuItem { icon:string; label: string; action: () => void; diff --git a/src/app/shared/system-service/file.service.ts b/src/app/shared/system-service/file.service.ts index 03fe2b22..cba4a45a 100644 --- a/src/app/shared/system-service/file.service.ts +++ b/src/app/shared/system-service/file.service.ts @@ -149,6 +149,47 @@ export class FileService{ }); } + public async copyHandler(arg0:string, sourcePathArg:string, destinationArg:string):Promise{ + + const checkIfDirResult = await this.checkIfDirectory(`${sourcePathArg}`); + if(checkIfDirResult){ + const folderName = this.getFileName(sourcePathArg); + const createFolderResult = await this.createFolderAsync(destinationArg, folderName); + if(createFolderResult){ + const loadedDirectoryEntries = await this.getEntriesFromDirectoryAsync(sourcePathArg); + for(const directoryEntry of loadedDirectoryEntries){ + const checkIfDirResult = await this.checkIfDirectory(`${sourcePathArg}/${directoryEntry}`); + if(checkIfDirResult){ + const result = await this.copyHandler(arg0,`${sourcePathArg}/${directoryEntry}`,`${destinationArg}/${folderName}`); + if(!result){ + console.log(`Failed to copy directory: ${sourcePathArg}/${directoryEntry}`); + return false; + } + }else{ + const result = await this.copyFileAsync(`${sourcePathArg}/${directoryEntry}`, `${destinationArg}/${folderName}`); + if(result){ + console.log(`file:${sourcePathArg}/${directoryEntry} successfully copied to destination:${destinationArg}/${folderName}`); + }else{ + console.log(`file:${sourcePathArg}/${directoryEntry} failed to copy to destination:${destinationArg}/${folderName}`) + return false + } + } + } + } + }else{ + const result = await this.copyFileAsync(`${sourcePathArg}`, `${destinationArg}`); + if(result){ + console.log(`file:${sourcePathArg} successfully copied to destination:${destinationArg}`); + }else{ + console.log(`file:${sourcePathArg} failed to copy to destination:${destinationArg}`) + return false + } + } + + return true + } + + public async createFolderAsync(directory:string, fileName:string):Promise{ return new Promise((resolve, reject) =>{ this._fileSystem.mkdir(`${directory}/${fileName}`,0o777,(err) =>{ @@ -489,6 +530,48 @@ export class FileService{ }); } + public async movehandler(destinationArg:string, folderQueue:string[]):Promise{ + + if(folderQueue.length === 0) + return true; + + const sourcePath = folderQueue.shift() || ''; + const folderName = this.getFileName(sourcePath); + + const checkIfDirResult = await this.checkIfDirectory(`${sourcePath}`); + if(checkIfDirResult){ + const loadedDirectoryEntries = await this.getEntriesFromDirectoryAsync(sourcePath); + const moveFolderResult = await this.createFolderAsync(destinationArg,folderName); + if(moveFolderResult){ + for(const directoryEntry of loadedDirectoryEntries){ + const checkIfDirResult = await this.checkIfDirectory(`${sourcePath}/${directoryEntry}`); + if(checkIfDirResult){ + folderQueue.push(`${sourcePath}/${directoryEntry}`); + }else{ + const result = await this.moveFileAsync(`${sourcePath}/${directoryEntry}`, `${destinationArg}/${folderName}`); + if(result){ + console.log(`file:${sourcePath}/${directoryEntry} successfully moved to destination:${destinationArg}/${folderName}`); + }else{ + console.log(`file:${sourcePath}/${directoryEntry} failed to move to destination:${destinationArg}/${folderName}`) + } + } + } + }else{ + console.log(`folder:${destinationArg}/${folderName} creation failed`); + return false; + } + }else{ + const result = await this.moveFileAsync(`${sourcePath}`,`${destinationArg}`); + if(result){ + console.log(`file:${sourcePath} successfully moved to destination:${destinationArg}`); + }else{ + console.log(`file:${sourcePath} failed to move to destination:${destinationArg}`) + } + } + + return this.movehandler(`${destinationArg}/${folderName}`, folderQueue); + } + public async writeFilesAsync(directory:string, files:File[]):Promise{ return new Promise((resolve, reject) =>{ @@ -542,6 +625,45 @@ export class FileService{ }); } + + public async removeHandler(arg0: string, sourceArg: string): Promise { + const loadedDirectoryEntries = await this.getEntriesFromDirectoryAsync(sourceArg); + + for (const directoryEntry of loadedDirectoryEntries) { + const entryPath = `${sourceArg}/${directoryEntry}`; + const checkIfDirectory = await this.checkIfDirectory(entryPath); + + if (checkIfDirectory) { + // Recursively call the rm_dir_handler for the subdirectory + const success = await this.removeHandler(arg0, entryPath); + if (!success) { + console.log(`Failed to delete directory: ${entryPath}`); + return false; + } + } else { + const result = await this.deleteFileAsync(entryPath); + if (result) { + console.log(`File: ${directoryEntry} in ${entryPath} deleted successfully`); + } else { + console.log(`File: ${directoryEntry} in ${entryPath} failed deletion`); + return false; + } + } + } + + // Delete the current directory after all its contents have been deleted + console.log(`folder to delete: ${sourceArg}`); + const result = await this.deleteFolderAsync(`${sourceArg}`); + + if (result) { + console.log(`Directory: ${sourceArg} deleted successfully`); + return true; + } else { + console.log(`Failed to delete directory: ${sourceArg}`); + return false; + } + } + public async renameAsync(path:string, newFileName:string, isFile:boolean): Promise { return new Promise((resolve, reject) =>{ @@ -566,6 +688,10 @@ export class FileService{ }); } + public resetDirectoryFiles(){ + this._directoryFileEntires=[] + } + //virtual filesystem, use copy and then delete public async moveFileAsync(currentPath:string, newPath:string): Promise { @@ -613,10 +739,6 @@ export class FileService{ return `${dirname(path)}/${filename} (${count})${extension}`; } - public resetDirectoryFiles(){ - this._directoryFileEntires=[] - } - public async setFolderValuesAsync(path: string):Promise{ return new Promise((resolve, reject) =>{ diff --git a/src/app/shared/system-service/menu.services.ts b/src/app/shared/system-service/menu.services.ts index 1b3c05bb..6c20a564 100644 --- a/src/app/shared/system-service/menu.services.ts +++ b/src/app/shared/system-service/menu.services.ts @@ -10,7 +10,9 @@ import { Process } from "src/app/system-files/process"; export class MenuService{ - private _isPasteActive = false + private _isPasteActive = false; + private _path = 'NOPATH'; + private _actions = ''; pinToTaskBar: Subject = new Subject(); unPinFromTaskBar: Subject = new Subject(); @@ -32,4 +34,20 @@ export class MenuService{ getPasteState():boolean{ return this._isPasteActive; } + + setPath(path:string):void{ + this._path = path; + } + + getPath():string{ + return this._path; + } + + setActions(action:string):void{ + this._actions = action; + } + + getActions():string{ + return this._actions; + } } \ No newline at end of file diff --git a/src/app/system-apps/desktop/desktop.component.ts b/src/app/system-apps/desktop/desktop.component.ts index 0abce049..4e744881 100644 --- a/src/app/system-apps/desktop/desktop.component.ts +++ b/src/app/system-apps/desktop/desktop.component.ts @@ -12,7 +12,7 @@ import { FileInfo } from 'src/app/system-files/fileinfo'; import { TriggerProcessService } from 'src/app/shared/system-service/trigger.process.service'; import { ScriptService } from 'src/app/shared/system-service/script.services'; import { MenuService } from 'src/app/shared/system-service/menu.services'; -import { DesktopMenu, DesktopMenuItem } from 'src/app/shared/system-component/menu/menu.item'; +import { NestedMenu, NestedMenuItem } from 'src/app/shared/system-component/menu/menu.item'; import * as htmlToImage from 'html-to-image'; import { FileService } from 'src/app/shared/system-service/file.service'; import { trigger, state, style, transition, animate } from '@angular/animations'; @@ -99,13 +99,7 @@ export class DesktopComponent implements OnInit, OnDestroy, AfterViewInit{ removeTskBarPrevWindowFromDOMTimeoutId!: NodeJS.Timeout; hideTskBarPrevWindowTimeoutId!: NodeJS.Timeout; - hasWindow = false; - icon = 'osdrive/icons/generic-program.ico'; - name = 'desktop'; - processId = 0; - type = ComponentType.System; - displayName = ''; - + directory ='/Desktop'; terminalApp ="terminal"; textEditorApp ="texteditor"; codeEditorApp ="codeeditor"; @@ -134,7 +128,15 @@ export class DesktopComponent implements OnInit, OnDestroy, AfterViewInit{ {icon:'', label: '', action: ()=> console.log() }, ]; - deskTopMenu:DesktopMenu[] = [] + deskTopMenu:NestedMenu[] = []; + + + hasWindow = false; + icon = 'osdrive/icons/generic-program.ico'; + name = 'desktop'; + processId = 0; + type = ComponentType.System; + displayName = ''; constructor( processIdService:ProcessIDService,runningProcessService:RunningProcessService,fileManagerServices:FileManagerService, @@ -282,9 +284,9 @@ export class DesktopComponent implements OnInit, OnDestroy, AfterViewInit{ } async createFolder():Promise{ - const directory ='/Desktop'; + const folderName = 'New Folder'; - const result = await this._fileService.createFolderAsync(directory, folderName); + const result = await this._fileService.createFolderAsync(this.directory, folderName); if(result){ this._fileService.addEventOriginator('filemanager'); this._fileService.dirFilesUpdateNotify.next(); @@ -436,6 +438,27 @@ export class DesktopComponent implements OnInit, OnDestroy, AfterViewInit{ this.openApplication(this.markDownViewerApp); } + async onPaste():Promise{ + const cntntPath = this._menuService.getPath(); + const action = this._menuService.getActions(); + + console.log(`path: ${cntntPath}`); + console.log(`action: ${action}`); + + if(action === 'copy'){ + const result = await this._fileService.copyHandler('',cntntPath,this.directory); + if(result){ + this.refresh(); + } + } + else if(action === 'cut'){ + const result = await this._fileService.movehandler(this.directory, [cntntPath]); + if(result){ + this.refresh(); + } + } + } + openApplication(arg0:string):void{ const file = new FileInfo(); @@ -450,24 +473,24 @@ export class DesktopComponent implements OnInit, OnDestroy, AfterViewInit{ } - buildViewByMenu():DesktopMenuItem[]{ + buildViewByMenu():NestedMenuItem[]{ - const smallIcon:DesktopMenuItem={ icon:'osdrive/icons/circle.png', label:'Small icons', action: this.viewBySmallIcon.bind(this), variables:this.isSmallIcon, + const smallIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Small icons', action: this.viewBySmallIcon.bind(this), variables:this.isSmallIcon, emptyline:false, styleOption:'A' } - const mediumIcon:DesktopMenuItem={ icon:'osdrive/icons/circle.png', label:'Medium icons', action: this.viewByMediumIcon.bind(this), variables:this.isMediumIcon, + const mediumIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Medium icons', action: this.viewByMediumIcon.bind(this), variables:this.isMediumIcon, emptyline:false, styleOption:'A' } - const largeIcon:DesktopMenuItem={ icon:'osdrive/icons/circle.png', label:'Large icons', action: this.viewByLargeIcon.bind(this), variables:this.isLargeIcon, + const largeIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Large icons', action: this.viewByLargeIcon.bind(this), variables:this.isLargeIcon, emptyline:true, styleOption:'A' } - const autoArrageIcon:DesktopMenuItem={ icon:'osdrive/icons/chkmark32.png', label:'Auto arrange icons', action: this.autoArrangeIcon.bind(this), variables:this.autoArrangeIcons, + const autoArrageIcon:NestedMenuItem={ icon:'osdrive/icons/chkmark32.png', label:'Auto arrange icons', action: this.autoArrangeIcon.bind(this), variables:this.autoArrangeIcons, emptyline:false, styleOption:'B' } - const autoAlign:DesktopMenuItem={ icon:'osdrive/icons/chkmark32.png', label:'Align icons to grid', action: this.autoAlignIcon.bind(this), variables:this.autoAlignIcons, + const autoAlign:NestedMenuItem={ icon:'osdrive/icons/chkmark32.png', label:'Align icons to grid', action: this.autoAlignIcon.bind(this), variables:this.autoAlignIcons, emptyline:true, styleOption:'B' } - const showDesktopIcons:DesktopMenuItem={ icon:'osdrive/icons/chkmark32.png', label:'Show desktop icons', action: this.showDesktopIcon.bind(this), variables:this.showDesktopIcons, + const showDesktopIcons:NestedMenuItem={ icon:'osdrive/icons/chkmark32.png', label:'Show desktop icons', action: this.showDesktopIcon.bind(this), variables:this.showDesktopIcons, emptyline:false, styleOption:'B'} const viewByMenu = [smallIcon,mediumIcon,largeIcon, autoArrageIcon, autoAlign,showDesktopIcons]; @@ -475,18 +498,18 @@ export class DesktopComponent implements OnInit, OnDestroy, AfterViewInit{ return viewByMenu; } - buildSortByMenu(): DesktopMenuItem[]{ + buildSortByMenu(): NestedMenuItem[]{ - const sortByName:DesktopMenuItem={ icon:'osdrive/icons/circle.png', label:'Name', action: this.sortByNameM.bind(this), variables:this.isSortByName , + const sortByName:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Name', action: this.sortByNameM.bind(this), variables:this.isSortByName , emptyline:false, styleOption:'A' } - const sortBySize:DesktopMenuItem={ icon:'osdrive/icons/circle.png', label:'Size', action: this.sortBySizeM.bind(this), variables:this.isSortBySize , + const sortBySize:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Size', action: this.sortBySizeM.bind(this), variables:this.isSortBySize , emptyline:false, styleOption:'A' } - const sortByItemType:DesktopMenuItem={ icon:'osdrive/icons/circle.png', label:'Item type', action: this.sortByItemTypeM.bind(this), variables:this.isSortByItemType, + const sortByItemType:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Item type', action: this.sortByItemTypeM.bind(this), variables:this.isSortByItemType, emptyline:false, styleOption:'A' } - const sortByDateModified:DesktopMenuItem={ icon:'osdrive/icons/circle.png', label:'Date modified', action: this.sortByDateModifiedM.bind(this), variables:this.isSortByDateModified, + const sortByDateModified:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Date modified', action: this.sortByDateModifiedM.bind(this), variables:this.isSortByDateModified, emptyline:false, styleOption:'A' } const sortByMenu = [sortByName, sortBySize, sortByItemType, sortByDateModified ] @@ -494,15 +517,15 @@ export class DesktopComponent implements OnInit, OnDestroy, AfterViewInit{ return sortByMenu } - buildNewMenu(): DesktopMenuItem[]{ + buildNewMenu(): NestedMenuItem[]{ - const newFolder:DesktopMenuItem={ icon:'osdrive/icons/empty_folder.ico', label:'Folder', action: this.createFolder.bind(this), variables:true , + const newFolder:NestedMenuItem={ icon:'osdrive/icons/empty_folder.ico', label:'Folder', action: this.createFolder.bind(this), variables:true , emptyline:false, styleOption:'C' } - const textEditor:DesktopMenuItem={ icon:'osdrive/icons/text-editor_48.png', label:'Rich Text', action: this.openTextEditor.bind(this), variables:true , + const textEditor:NestedMenuItem={ icon:'osdrive/icons/text-editor_48.png', label:'Rich Text', action: this.openTextEditor.bind(this), variables:true , emptyline:false, styleOption:'C' } - const codeEditor:DesktopMenuItem={ icon:'osdrive/icons/vs-code_48.png', label:'Code Editor', action: this.openCodeEditor.bind(this), variables:true , + const codeEditor:NestedMenuItem={ icon:'osdrive/icons/vs-code_48.png', label:'Code Editor', action: this.openCodeEditor.bind(this), variables:true , emptyline:false, styleOption:'C' } const sortByMenu = [newFolder, textEditor, codeEditor ] @@ -515,7 +538,7 @@ export class DesktopComponent implements OnInit, OnDestroy, AfterViewInit{ {icon1:'', icon2: 'osdrive/icons/arrow_next.png', label:'View', nest:this.buildViewByMenu(), action: ()=> console.log(), emptyline:false}, {icon1:'', icon2:'osdrive/icons/arrow_next.png', label:'Sort by', nest:this.buildSortByMenu(), action: ()=> console.log(), emptyline:false}, {icon1:'', icon2:'', label: 'Refresh', nest:[], action:this.refresh.bind(this), emptyline:true}, - {icon1:'', icon2:'', label: 'Paste', nest:[], action: () => console.log('Paste!! Paste!!'), emptyline:false}, + {icon1:'', icon2:'', label: 'Paste', nest:[], action:this.onPaste.bind(this), emptyline:false}, {icon1:'/osdrive/icons/terminal_48.png', icon2:'', label:'Open in Terminal', nest:[], action: this.openTerminal.bind(this), emptyline:false}, {icon1:'/osdrive/icons/camera_48.png', icon2:'', label:'Screen Shot', nest:[], action: this.captureComponentImg.bind(this), emptyline:false}, {icon1:'', icon2:'', label:'Next Background', nest:[], action: this.nextBackground.bind(this), emptyline:false}, diff --git a/src/app/system-apps/fileexplorer/fileexplorer.component.ts b/src/app/system-apps/fileexplorer/fileexplorer.component.ts index 023ab2c4..0c349006 100644 --- a/src/app/system-apps/fileexplorer/fileexplorer.component.ts +++ b/src/app/system-apps/fileexplorer/fileexplorer.component.ts @@ -17,6 +17,7 @@ import {basename} from 'path'; import { AppState, BaseState } from 'src/app/system-files/state/state.interface'; import { StateType } from 'src/app/system-files/state/state.type'; import { SessionManagmentService } from 'src/app/shared/system-service/session.management.service'; +import { NestedMenu, NestedMenuItem } from 'src/app/shared/system-component/menu/menu.item'; import { Constants } from 'src/app/system-files/constants'; import * as htmlToImage from 'html-to-image'; import { TaskBarPreviewImage } from '../taskbarpreview/taskbar.preview'; @@ -840,15 +841,14 @@ export class FileExplorerComponent implements BaseComponent, OnInit, AfterViewIn onCopy():void{ const action = 'copy'; - const result = this.selectedFile.getCurrentPath; - this._menuService.storeData.next([result, action]); + const path = this.selectedFile.getCurrentPath; + this._menuService.storeData.next([path, action]); } onCut():void{ - const action = 'copy'; - const action1 = 'remove'; - const result = this.selectedFile.getCurrentPath; - this._menuService.storeData.next([result, action, action1]); + const action = 'cut'; + const path = this.selectedFile.getCurrentPath; + this._menuService.storeData.next([path, action]); } onHideIconContextMenu():void{ @@ -1416,6 +1416,88 @@ export class FileExplorerComponent implements BaseComponent, OnInit, AfterViewIn } } + + + // buildViewByMenu():NestedMenuItem[]{ + + // const extraLargeIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Extra Large icons', action: this.viewBySmallIcon.bind(this), variables:this., + // emptyline:false, styleOption:'A' } + + // const largeIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Large icons', action: this.viewByMediumIcon.bind(this), variables:this.isMediumIcon, + // emptyline:false, styleOption:'A' } + + // const mediumIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Medium icons', action: this.viewByLargeIcon.bind(this), variables:this.isLargeIcon, + // emptyline:true, styleOption:'A' } + + // const smallIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Medium icons', action: this.viewByLargeIcon.bind(this), variables:this.isLargeIcon, + // emptyline:true, styleOption:'A' } + + // const listIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Medium icons', action: this.viewByLargeIcon.bind(this), variables:this.isLargeIcon, + // emptyline:true, styleOption:'A' } + + // const detailsIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Medium icons', action: this.viewByLargeIcon.bind(this), variables:this.isLargeIcon, + // emptyline:true, styleOption:'A' } + + // const titlesIcon:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Medium icons', action: this.viewByLargeIcon.bind(this), variables:this.isLargeIcon, + // emptyline:true, styleOption:'A' } + + + + // const viewByMenu = [extraLargeIcon, largeIcon, mediumIcon, smallIcon, listIcon,detailsIcon, titlesIcon]; + + // return viewByMenu; + // } + + // buildSortByMenu(): NestedMenuItem[]{ + + // const sortByName:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Name', action: this.sortByNameM.bind(this), variables:this.isSortByName , + // emptyline:false, styleOption:'A' } + + // const sortBySize:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Size', action: this.sortBySizeM.bind(this), variables:this.isSortBySize , + // emptyline:false, styleOption:'A' } + + // const sortByItemType:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Item type', action: this.sortByItemTypeM.bind(this), variables:this.isSortByItemType, + // emptyline:false, styleOption:'A' } + + // const sortByDateModified:NestedMenuItem={ icon:'osdrive/icons/circle.png', label:'Date modified', action: this.sortByDateModifiedM.bind(this), variables:this.isSortByDateModified, + // emptyline:false, styleOption:'A' } + + // const sortByMenu = [sortByName, sortBySize, sortByItemType, sortByDateModified ] + + // return sortByMenu + // } + + // buildNewMenu(): NestedMenuItem[]{ + + // const newFolder:NestedMenuItem={ icon:'osdrive/icons/empty_folder.ico', label:'Folder', action: this.createFolder.bind(this), variables:true , + // emptyline:false, styleOption:'C' } + + // const textEditor:NestedMenuItem={ icon:'osdrive/icons/text-editor_48.png', label:'Rich Text', action: this.openTextEditor.bind(this), variables:true , + // emptyline:false, styleOption:'C' } + + // const codeEditor:NestedMenuItem={ icon:'osdrive/icons/vs-code_48.png', label:'Code Editor', action: this.openCodeEditor.bind(this), variables:true , + // emptyline:false, styleOption:'C' } + + // const sortByMenu = [newFolder, textEditor, codeEditor ] + + // return sortByMenu + // } + + // getDesktopMenuData():void{ + // this.deskTopMenu = [ + // {icon1:'', icon2: 'osdrive/icons/arrow_next.png', label:'View', nest:this.buildViewByMenu(), action: ()=> console.log(), emptyline:false}, + // {icon1:'', icon2:'osdrive/icons/arrow_next.png', label:'Sort by', nest:this.buildSortByMenu(), action: ()=> console.log(), emptyline:false}, + // {icon1:'', icon2:'', label: 'Refresh', nest:[], action:this.refresh.bind(this), emptyline:true}, + // {icon1:'', icon2:'', label: 'Paste', nest:[], action: () => console.log('Paste!! Paste!!'), emptyline:false}, + // {icon1:'/osdrive/icons/terminal_48.png', icon2:'', label:'Open in Terminal', nest:[], action: this.openTerminal.bind(this), emptyline:false}, + // {icon1:'/osdrive/icons/camera_48.png', icon2:'', label:'Screen Shot', nest:[], action: this.captureComponentImg.bind(this), emptyline:false}, + // {icon1:'', icon2:'', label:'Next Background', nest:[], action: this.nextBackground.bind(this), emptyline:false}, + // {icon1:'', icon2:'', label:'Previous Background', nest:[], action: this.previousBackground.bind(this), emptyline:true}, + // {icon1:'', icon2:'osdrive/icons/arrow_next.png', label:'New', nest:this.buildNewMenu(), action: ()=> console.log(), emptyline:true}, + // {icon1:'', icon2:'', label:'Many Thanks', nest:[], action: this.openMarkDownViewer.bind(this), emptyline:false} + // ] + // } + private getComponentDetail():Process{ return new Process(this.processId, this.name, this.icon, this.hasWindow, this.type); } diff --git a/src/app/system-apps/filemanager/filemanager.component.ts b/src/app/system-apps/filemanager/filemanager.component.ts index 7d9117e4..a00ae158 100644 --- a/src/app/system-apps/filemanager/filemanager.component.ts +++ b/src/app/system-apps/filemanager/filemanager.component.ts @@ -224,17 +224,15 @@ export class FileManagerComponent implements BaseComponent, OnInit, AfterViewIni onCopy():void{ const action = 'copy'; - const result = this.selectedFile.getCurrentPath; - this._menuService.storeData.next([result, action]); + const path = this.selectedFile.getCurrentPath; + this._menuService.storeData.next([path, action]); } onCut():void{ - const action = 'copy'; - const action1 = 'remove'; - const result = this.selectedFile.getCurrentPath; - this._menuService.storeData.next([result, action, action1]); + const action = 'cut'; + const path = this.selectedFile.getCurrentPath; + this._menuService.storeData.next([path, action]); } - pinIconToTaskBar():void{ this._menuService.pinToTaskBar.next(this.selectedFile); } diff --git a/src/app/system-apps/terminal/terminal.commands.ts b/src/app/system-apps/terminal/terminal.commands.ts index 590d0ff8..77c10fb5 100644 --- a/src/app/system-apps/terminal/terminal.commands.ts +++ b/src/app/system-apps/terminal/terminal.commands.ts @@ -518,7 +518,7 @@ usage: mkdir direcotry_name [-v] return 'destination path required'; folderQueue.push(sourceArg); - const result = await this.mvhandler(destinationArg, folderQueue); + const result = await this._fileService.movehandler(destinationArg, folderQueue); if(result){ const result = await this.rm('-rf', sourceArg); if(result === ''){ @@ -534,49 +534,6 @@ usage: mkdir direcotry_name [-v] return '' } - private async mvhandler(destinationArg:string, folderQueue:string[]):Promise{ - - if(folderQueue.length === 0) - return true; - - const sourcePath = folderQueue.shift() || ''; - const folderName = this.getFileName(sourcePath); - - const checkIfDirResult = await this._fileService.checkIfDirectory(`${sourcePath}`); - if(checkIfDirResult){ - const loadedDirectoryEntries = await this._fileService.getEntriesFromDirectoryAsync(sourcePath); - const moveFolderResult = await this._fileService.createFolderAsync(destinationArg,folderName); - if(moveFolderResult){ - for(const directoryEntry of loadedDirectoryEntries){ - const checkIfDirResult = await this._fileService.checkIfDirectory(`${sourcePath}/${directoryEntry}`); - if(checkIfDirResult){ - folderQueue.push(`${sourcePath}/${directoryEntry}`); - }else{ - const result = await this._fileService.moveFileAsync(`${sourcePath}/${directoryEntry}`, `${destinationArg}/${folderName}`); - if(result){ - console.log(`file:${sourcePath}/${directoryEntry} successfully moved to destination:${destinationArg}/${folderName}`); - }else{ - console.log(`file:${sourcePath}/${directoryEntry} failed to move to destination:${destinationArg}/${folderName}`) - } - } - } - }else{ - console.log(`folder:${destinationArg}/${folderName} creation failed`); - return false; - } - }else{ - const result = await this._fileService.moveFileAsync(`${sourcePath}`,`${destinationArg}`); - if(result){ - console.log(`file:${sourcePath} successfully moved to destination:${destinationArg}`); - }else{ - console.log(`file:${sourcePath} failed to move to destination:${destinationArg}`) - } - } - - return this.mvhandler(`${destinationArg}/${folderName}`, folderQueue); - } - - async cp(optionArg:any, sourceArg:string, destinationArg:string):Promise{ console.log(`copy-source ${optionArg}`); @@ -633,7 +590,7 @@ Mandatory argument to long options are mandotory for short options too. if(option === '-r' || (option === '-R' || option === '--recursive')){ folderQueue.push(sourceArg); //const result = await this.cp_dir_handler(optionArg,destinationArg, folderQueue); - const result = await this.cpHandler(optionArg,sourceArg, destinationArg); + const result = await this._fileService.copyHandler(optionArg,sourceArg, destinationArg); if(result){ this.sendDirectoryUpdateNotification(destinationArg); } @@ -641,7 +598,7 @@ Mandatory argument to long options are mandotory for short options too. }else{ // just copy regular file //const result = await this.cp_file_handler(sourceArg,destinationArg); - const result = await this.cpHandler(optionArg,sourceArg, destinationArg); + const result = await this._fileService.copyHandler(optionArg,sourceArg, destinationArg); if(result){ this.sendDirectoryUpdateNotification(destinationArg); } @@ -649,46 +606,6 @@ Mandatory argument to long options are mandotory for short options too. return ''; } - private async cpHandler(arg0:string, sourcePathArg:string, destinationArg:string):Promise{ - - const checkIfDirResult = await this._fileService.checkIfDirectory(`${sourcePathArg}`); - if(checkIfDirResult){ - const folderName = this.getFileName(sourcePathArg); - const createFolderResult = await this._fileService.createFolderAsync(destinationArg, folderName); - if(createFolderResult){ - const loadedDirectoryEntries = await this._fileService.getEntriesFromDirectoryAsync(sourcePathArg); - for(const directoryEntry of loadedDirectoryEntries){ - const checkIfDirResult = await this._fileService.checkIfDirectory(`${sourcePathArg}/${directoryEntry}`); - if(checkIfDirResult){ - const result = await this.cpHandler(arg0,`${sourcePathArg}/${directoryEntry}`,`${destinationArg}/${folderName}`); - if(!result){ - console.log(`Failed to copy directory: ${sourcePathArg}/${directoryEntry}`); - return false; - } - }else{ - const result = await this._fileService.copyFileAsync(`${sourcePathArg}/${directoryEntry}`, `${destinationArg}/${folderName}`); - if(result){ - console.log(`file:${sourcePathArg}/${directoryEntry} successfully copied to destination:${destinationArg}/${folderName}`); - }else{ - console.log(`file:${sourcePathArg}/${directoryEntry} failed to copy to destination:${destinationArg}/${folderName}`) - return false - } - } - } - } - }else{ - const result = await this._fileService.copyFileAsync(`${sourcePathArg}`, `${destinationArg}`); - if(result){ - console.log(`file:${sourcePathArg} successfully copied to destination:${destinationArg}`); - }else{ - console.log(`file:${sourcePathArg} failed to copy to destination:${destinationArg}`) - return false - } - } - - return true - } - async rm(optionArg:any, sourceArg:string):Promise{ console.log(`source ${optionArg}`); @@ -734,7 +651,7 @@ Mandatory argument to long options are mandotory for short options too. if(option === '-rf'){ folderQueue.push(sourceArg); - const result = await this.rmHandler(optionArg,sourceArg); + const result = await this._fileService.removeHandler(optionArg,sourceArg); if(result){ this.sendDirectoryUpdateNotification(sourceArg); return ''; @@ -742,7 +659,7 @@ Mandatory argument to long options are mandotory for short options too. } }else{ // just copy regular file - const result = await this.rmHandler(sourceArg,sourceArg); + const result = await this._fileService.removeHandler(sourceArg,sourceArg); if(result){ this.sendDirectoryUpdateNotification(sourceArg); return ''; @@ -751,49 +668,6 @@ Mandatory argument to long options are mandotory for short options too. return 'error'; } - private async rmHandler(arg0: string, sourceArg: string): Promise { - const loadedDirectoryEntries = await this._fileService.getEntriesFromDirectoryAsync(sourceArg); - - for (const directoryEntry of loadedDirectoryEntries) { - const entryPath = `${sourceArg}/${directoryEntry}`; - const checkIfDirectory = await this._fileService.checkIfDirectory(entryPath); - - if (checkIfDirectory) { - // Recursively call the rm_dir_handler for the subdirectory - const success = await this.rmHandler(arg0, entryPath); - if (!success) { - console.log(`Failed to delete directory: ${entryPath}`); - return false; - } - } else { - const result = await this._fileService.deleteFileAsync(entryPath); - if (result) { - console.log(`File: ${directoryEntry} in ${entryPath} deleted successfully`); - } else { - console.log(`File: ${directoryEntry} in ${entryPath} failed deletion`); - return false; - } - } - } - - // Delete the current directory after all its contents have been deleted - console.log(`folder to delete: ${sourceArg}`); - const result = await this._fileService.deleteFolderAsync(`${sourceArg}`); - - if (result) { - console.log(`Directory: ${sourceArg} deleted successfully`); - return true; - } else { - console.log(`Failed to delete directory: ${sourceArg}`); - return false; - } - } - - - private getFileName(path:string):string{ - return `${basename(path, extname(path))}${ extname(path)}`; - } - private sendDirectoryUpdateNotification(arg0:string):void{ if(arg0.includes('/Desktop')){ this._fileService.addEventOriginator('filemanager'); diff --git a/src/osdrive/Games/D3D.url b/src/osdrive/Games/D3D.url index fc47d9ae..f46545cf 100644 --- a/src/osdrive/Games/D3D.url +++ b/src/osdrive/Games/D3D.url @@ -2,5 +2,5 @@ FileName=D3D IconPath=/osdrive/Games/icons/d3d.png FileType=.jsdos -ContentPath=/osdrive/Games/data/D3D.jsdos +ContentPath=/osdrive/Games/Data/D3D.jsdos OpensWith=jsdos diff --git a/src/osdrive/Games/Diggers.url b/src/osdrive/Games/Diggers.url index 9730ea04..84c2ff72 100644 --- a/src/osdrive/Games/Diggers.url +++ b/src/osdrive/Games/Diggers.url @@ -2,5 +2,5 @@ FileName=Diggers IconPath=/osdrive/Games/icons/diggers.png FileType=.jsdos -ContentPath=/osdrive/Games/data/Digger.jsdos +ContentPath=/osdrive/Games/Data/Digger.jsdos OpensWith=jsdos diff --git a/src/osdrive/Games/Doom.url b/src/osdrive/Games/Doom.url index d3015986..efac69eb 100644 --- a/src/osdrive/Games/Doom.url +++ b/src/osdrive/Games/Doom.url @@ -2,5 +2,5 @@ FileName=Doom IconPath=/osdrive/Games/icons/doom.png FileType=.jsdos -ContentPath=/osdrive/Games/data/Doom.jsdos +ContentPath=/osdrive/Games/Data/Doom.jsdos OpensWith=jsdos