aboutsummaryrefslogtreecommitdiffstats
path: root/Library/UefiShellUfmCommandLib/actions.c
blob: 174eb3e6ae9521be9d8c93a4dbdf4c9f809aa3ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/ShellLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>

#include "dir.h"
#include "fs.h"

#include "menu-bar.h"
#include "command-bar.h"
#include "dialog-box.h"
#include "panel.h"
#include "filemanager.h"
#include "cmds.h"
#include "actions.h"

#define MENUBAR (fm_ctx.menubar)
#define CMDBAR (fm_ctx.cmdbar)
#define PANEL (fm_ctx.curpanel)
#define LEFT_PANEL (fm_ctx.left)
#define RIGHT_PANEL (fm_ctx.right)

STATIC CONST CHAR16 mkdir_title[] = L" Create a new directory ";
STATIC CONST CHAR16 mkdir_label[] = L"Enter directory name:";

STATIC EFI_STATUS shell_exec2(CONST CHAR16 *farg,
	CONST CHAR16 *sarg, EFI_STATUS *cmd_status)
{
	EFI_STATUS status;
	CHAR16 *cmd_line = NULL;
	UINTN size = 0;

	StrnCatGrow(&cmd_line, &size, farg, 0);
	StrnCatGrow(&cmd_line, &size, sarg, 0);
	status = ShellExecute(&gImageHandle, cmd_line, FALSE, NULL, cmd_status);
	SHELL_FREE_NON_NULL(cmd_line);
	return status;
}

STATIC VOID redraw()
{
	panel_refresh(LEFT_PANEL);
	panel_refresh(RIGHT_PANEL);
	menubar_refresh(MENUBAR);
	cmdbar_refresh(CMDBAR);
}

BOOLEAN jump_up(VOID)
{
	panel_move_cursor(PANEL, PANEL->curline - 1);
	return TRUE;
}

BOOLEAN jump_down(VOID)
{
	panel_move_cursor(PANEL, PANEL->curline + 1);
	return TRUE;
}

BOOLEAN change_panel(VOID)
{
	panel_set_active(PANEL, FALSE);
	PANEL = (PANEL == LEFT_PANEL) ? RIGHT_PANEL : LEFT_PANEL;
	panel_set_active(PANEL, TRUE);
	return TRUE;
}

BOOLEAN execute(VOID)
{
	EFI_SHELL_FILE_INFO *file;
	EFI_STATUS cmd_status;

	if(!PANEL->cwd)
		return panel_cd_to(PANEL, PANEL->fsa->full_name[PANEL->curline-1]);
	
	file = dirl_getn(PANEL->dirs, PANEL->curline);
	if((file->Info->Attribute & EFI_FILE_DIRECTORY) != 0)
		return panel_cd_to(PANEL, file->FullName);

	shell_exec2(L"", file->FullName, &cmd_status);
	redraw();
	return TRUE;
}

BOOLEAN mark(VOID)
{
	panel_mark_file(PANEL, PANEL->curline);
	return TRUE;
}

BOOLEAN edit(VOID)
{
	EFI_SHELL_FILE_INFO *file;
	EFI_STATUS cmd_status;

	if(!PANEL->cwd)
		return FALSE;

	file = dirl_getn(PANEL->dirs, PANEL->curline);
	if((file->Info->Attribute & EFI_FILE_DIRECTORY) != 0)
		return FALSE;

	shell_exec2(L"edit ", file->FullName, &cmd_status);
	redraw();
	return TRUE;
}

BOOLEAN hexedit(VOID)
{
	EFI_SHELL_FILE_INFO *file;
	EFI_STATUS cmd_status;

	if(!PANEL->cwd)
		return FALSE;

	file = dirl_getn(PANEL->dirs, PANEL->curline);
	if((file->Info->Attribute & EFI_FILE_DIRECTORY) != 0)
		return FALSE;

	shell_exec2(L"hexedit ", file->FullName, &cmd_status);
	redraw();
	return TRUE;
}

BOOLEAN mkdir(VOID)
{
	struct dbox_ctx *dbox;
	UINTN line = PANEL->curline;
	EFI_STATUS status;
	BOOLEAN status_op;

	if(!PANEL->cwd)
		return FALSE;

	dbox = dbox_alloc(fm_ctx.scr, mkdir_title, mkdir_label, TRUE, L"");
	if(!dbox)
		return FALSE;

	dbox_refresh(dbox);
	status_op = dbox_handle(dbox);
	if(status_op) {
		status = make_directory(dbox->in->buffer);
		if(status == EFI_SUCCESS) {
			panel_cd_to(PANEL, PANEL->cwd);
			panel_move_cursor(PANEL, line);
		}
	}

	redraw();
	dbox_release(dbox);
	return TRUE;
}

BOOLEAN show_filesystems(VOID)
{
	return panel_cd_to(PANEL, NULL);
}

BOOLEAN do_nothing(VOID)
{
	return TRUE;
}

BOOLEAN quit(VOID)
{
	fm_ctx.flag_run = FALSE;
	return TRUE;
}