Skip to content

Commit abef104

Browse files
committed
* Cabinet: Can now launch directly into a directory instead of just root.
* Minesweeper: Use consistent mine icon * Shift the icon for minesweeper by 1 pixel Note: The cabinet change also affects the finder due to it using LaunchFileOrResource.
1 parent f95e0a5 commit abef104

File tree

6 files changed

+88
-20
lines changed

6 files changed

+88
-20
lines changed

apps/Minesweeper/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ int main()
954954
bRequestingNewSize = false;
955955

956956
Window* pWindow = g_pWindow = CreateWindow ("Minesweeper", minesweeperX, minesweeperY, MINESW_WIDTH, MINESW_HEIGHT, PrgMineProc, 0);
957-
SetWindowIcon (pWindow, ICON_BOMB);
957+
SetWindowIcon (pWindow, ICON_BOMB_SPIKEY);
958958

959959
if (!pWindow)
960960
{

fs/Bin/Minesweeper.nse

0 Bytes
Binary file not shown.

fs/Res/Icons/bomb16.png

4 Bytes
Loading

include/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum
3232
RESOURCE_EXWINDOW,
3333
RESOURCE_HELP,
3434
RESOURCE_IMAGE,
35+
RESOURCE_DIRECTORY,
3536
};
3637

3738
enum

src/resource.c

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ RESOURCE_STATUS CabinetExecute(const char* filename)
5050

5151
RESOURCE_STATUS CabinetExecuteScript(const char* pFileName)
5252
{
53+
if (strlen(pFileName) >= 500)
54+
return RESOURCE_LAUNCH_OUT_OF_MEMORY;
55+
5356
char *buffer = (char*)MmAllocate(512);
5457
strcpy (buffer, "ec ");
5558
strcat (buffer, pFileName);
5659
strcat (buffer, "\n");
5760

5861
// Create the Launch Executable thread with the file descriptor as its parameter.
5962
int errorCode = 0;
60-
Task* pTask = KeStartTask (TerminalHostTask, (int)buffer, &errorCode);
63+
Task* pTask = KeStartTask (TerminalHostTask, (long)buffer, &errorCode);
6164
if (errorCode != TASK_SUCCESS)
6265
{
6366
MmFree(buffer);
@@ -77,13 +80,41 @@ RESOURCE_STATUS CabinetExecuteScript(const char* pFileName)
7780
return RESOURCE_LAUNCH_SUCCESS;
7881
}
7982

83+
RESOURCE_STATUS CabinetLaunchDirectory(const char* pFileName)
84+
{
85+
if (strlen(pFileName) >= 511)
86+
return RESOURCE_LAUNCH_OUT_OF_MEMORY;
87+
88+
char *buffer = (char*)MmAllocate(512);
89+
strcpy (buffer, pFileName);
90+
91+
// Create the Launch Executable thread with the file descriptor as its parameter.
92+
int errorCode = 0;
93+
Task* pTask = KeStartTask (CabinetEntry, (long)buffer, &errorCode);
94+
if (errorCode != TASK_SUCCESS)
95+
{
96+
MmFree(buffer);
97+
char buffer1[1024];
98+
sprintf (buffer1, "Cannot create thread to execute '%s'. Out of memory?", pFileName);
99+
MessageBox(NULL, buffer1, "Error", ICON_ERROR << 16 | MB_OK);
100+
101+
return RESOURCE_LAUNCH_OUT_OF_MEMORY;
102+
}
103+
104+
KeUnsuspendTask(pTask);
105+
KeDetachTask(pTask);
106+
107+
// Consider it done. CabinetEntry task shall now MmFree the string allocated.
108+
return RESOURCE_LAUNCH_SUCCESS;
109+
}
110+
80111
RESOURCE_STATUS NotepadLaunchResource(const char* pResource)
81112
{
82113
char *buffer = (char*)MmAllocate(512);
83114
strcpy (buffer, pResource);
84115

85116
int errorCode = 0;
86-
Task* pTask = KeStartTask(BigTextEntry, (int)buffer, &errorCode);
117+
Task* pTask = KeStartTask(BigTextEntry, (long)buffer, &errorCode);
87118
if (errorCode != TASK_SUCCESS)
88119
{
89120
MmFree(buffer);
@@ -109,7 +140,7 @@ RESOURCE_STATUS ScribbleLaunchResource(const char* pResource)
109140
strcpy (buffer, pResource);
110141

111142
int errorCode = 0;
112-
Task* pTask = KeStartTask(PrgPaintTask, (int)buffer, &errorCode);
143+
Task* pTask = KeStartTask(PrgPaintTask, (long)buffer, &errorCode);
113144
if (errorCode != TASK_SUCCESS)
114145
{
115146
MmFree(buffer);
@@ -147,6 +178,7 @@ const RESOURCE_INVOKE g_ResourceInvokes[] = {
147178
CabinetExecute,//RESOURCE_EXWINDOW
148179
HelpOpenResource,//RESOURCE_HELP
149180
ScribbleLaunchResource,//RESOURCE_IMAGE
181+
CabinetLaunchDirectory,//RESOURCE_DIRECTORY
150182
};
151183

152184
RESOURCE_TYPE ResolveProtocolString(const char* protocol)
@@ -159,6 +191,7 @@ RESOURCE_TYPE ResolveProtocolString(const char* protocol)
159191
if (STREQ(protocol, "exwindow")) return RESOURCE_EXWINDOW;
160192
if (STREQ(protocol, "help")) return RESOURCE_HELP;
161193
if (STREQ(protocol, "image")) return RESOURCE_IMAGE;
194+
if (STREQ(protocol, "cabinet")) return RESOURCE_DIRECTORY;
162195
return RESOURCE_NONE;
163196
}
164197

@@ -248,9 +281,16 @@ RESOURCE_STATUS LaunchFileOrResource(const char* pResource)
248281
if (res < 0)
249282
return RESOURCE_LAUNCH_NOT_FOUND;
250283

251-
FileAssociation* pAssoc = ResolveAssociation(pResource, sr.m_type);
252-
253-
RESOURCE_TYPE resourceType = ResolveProtocolString(pAssoc->protocol);
284+
RESOURCE_TYPE resourceType;
285+
if (sr.m_type & FILE_TYPE_DIRECTORY)
286+
{
287+
resourceType = RESOURCE_DIRECTORY;
288+
}
289+
else
290+
{
291+
FileAssociation* pAssoc = ResolveAssociation(pResource, sr.m_type);
292+
resourceType = ResolveProtocolString(pAssoc->protocol);
293+
}
254294
if (resourceType == RESOURCE_NONE)
255295
return RESOURCE_LAUNCH_INVALID_PROTOCOL;
256296

src/wapp/cabinet/main.c

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
// This is still a work in progress.
1414
#define C_MAX_STATS_BEFORE_QUIT (256)
1515

16-
#define TABLE_COLUMNS (3)
16+
#define TABLE_COLUMNS (4)
1717

1818
//TODO: Move this to its own space.
1919
typedef struct
2020
{
2121
char m_cabinetCWD[PATH_MAX+2];
2222
char m_cbntOldCWD[PATH_MAX+2];
2323
bool m_bUsingTableView;
24+
char*m_pDestCWD;
2425
}
2526
CabData;
2627

@@ -45,6 +46,7 @@ void FormatSizeDetailed(uint32_t size, char* size_buf)
4546

4647
#define g_cabinetCWD (((CabData*)pWindow->m_data)->m_cabinetCWD)
4748
#define g_cbntOldCWD (((CabData*)pWindow->m_data)->m_cbntOldCWD)
49+
#define g_pDestCWD (((CabData*)pWindow->m_data)->m_pDestCWD)
4850
#define g_bUsingTableView (((CabData*)pWindow->m_data)->m_bUsingTableView)
4951

5052
enum
@@ -103,6 +105,7 @@ static void ClearFileListing(Window * pWindow)
103105
AddTableColumn(pWindow, MAIN_LISTVIEW, "Name", 200);
104106
AddTableColumn(pWindow, MAIN_LISTVIEW, "Size", 100);
105107
AddTableColumn(pWindow, MAIN_LISTVIEW, "Last modified date", 150);
108+
AddTableColumn(pWindow, MAIN_LISTVIEW, "File type", 150);
106109
}
107110
else
108111
{
@@ -123,7 +126,7 @@ static void ChangeListViewMode(Window* pWindow)
123126
}
124127

125128
// size = -1, means don't show anything to the file
126-
static void AddFileElementToList(Window* pWindow, const char * text, int icon, uint32_t file_size, int last_modified_date, bool is_symlink)
129+
static void AddFileElementToList(Window* pWindow, const char * text, int icon, uint32_t file_size, int last_modified_date, bool is_symlink, const char * description)
127130
{
128131
if (is_symlink)
129132
icon |= ICON_SHORTCUT_FLAG;
@@ -148,6 +151,7 @@ static void AddFileElementToList(Window* pWindow, const char * text, int icon, u
148151
table[0] = text;
149152
table[1] = size_buf;
150153
table[2] = date_buf;
154+
table[3] = description;
151155

152156
AddTableRow(pWindow, MAIN_LISTVIEW, table, icon);
153157
}
@@ -165,7 +169,7 @@ static void UpdateDirectoryListing (Window* pWindow)
165169

166170
if (strcmp (g_cabinetCWD, "/")) //if can go to parent, add a button
167171
{
168-
AddFileElementToList(pWindow, "..", ICON_FOLDER_PARENT, -1, -1, false);
172+
AddFileElementToList(pWindow, "..", ICON_FOLDER_PARENT, -1, -1, false, "Up one level");
169173
}
170174

171175
DirEnt ent, *pEnt = &ent;
@@ -205,8 +209,8 @@ static void UpdateDirectoryListing (Window* pWindow)
205209
if (res < 0)
206210
{
207211
char buf[512];
208-
sprintf(buf, "%s (can't stat -- %s)", pEnt->m_name, GetErrNoString(res));
209-
AddFileElementToList(pWindow, buf, ICON_ERROR, -1, -1, false);
212+
sprintf(buf, "%s (cannot stat)", pEnt->m_name, GetErrNoString(res));
213+
AddFileElementToList(pWindow, buf, ICON_ERROR, -1, -1, false, GetErrNoString(res));
210214
}
211215
else if (pEnt->m_type == FILE_TYPE_SYMBOLIC_LINK && filesDone < C_MAX_STATS_BEFORE_QUIT)
212216
{
@@ -215,7 +219,7 @@ static void UpdateDirectoryListing (Window* pWindow)
215219
if (res < 0)
216220
{
217221
// TODO: ICON_CHAIN_BROKEN
218-
AddFileElementToList(pWindow, pEnt->m_name, ICON_CHAIN_BROKEN, (pEnt->m_type != FILE_TYPE_FILE) ? (-1) : statResult.m_size, statResult.m_modifyTime, true);
222+
AddFileElementToList(pWindow, pEnt->m_name, ICON_CHAIN_BROKEN, (pEnt->m_type != FILE_TYPE_FILE) ? (-1) : statResult.m_size, statResult.m_modifyTime, true, "Broken symbolic link");
219223
}
220224
else
221225
{
@@ -226,8 +230,11 @@ static void UpdateDirectoryListing (Window* pWindow)
226230
}
227231
else
228232
{
233+
FileAssociation* pAssoc;
229234
stat_done:
230-
AddFileElementToList(pWindow, pEnt->m_name, CabGetIconBasedOnName(pName, pEnt->m_type), (pEnt->m_type != FILE_TYPE_FILE) ? (-1) : statResult.m_size, statResult.m_modifyTime, bIsSymLink);
235+
pAssoc = ResolveAssociation(pName, pEnt->m_type);
236+
237+
AddFileElementToList(pWindow, pEnt->m_name, pAssoc->icon, (pEnt->m_type != FILE_TYPE_FILE) ? (-1) : statResult.m_size, statResult.m_modifyTime, bIsSymLink, pAssoc->description);
231238
}
232239
}
233240

@@ -543,7 +550,16 @@ void CALLBACK CabinetWindowProc (Window* pWindow, int messageType, long parm1, l
543550
AddMenuBarItem(pWindow, MAIN_MENU_BAR, MENU$HELP, MENU$HELP$ABOUT, "About File Cabinet");
544551
}
545552

546-
CabinetChangeDirectory(pWindow, "/", false);
553+
if (g_pDestCWD)
554+
{
555+
CabinetChangeDirectory(pWindow, g_pDestCWD, true);
556+
MmFree(g_pDestCWD);
557+
g_pDestCWD = NULL;
558+
}
559+
else
560+
{
561+
CabinetChangeDirectory(pWindow, "/", false);
562+
}
547563

548564
// Add the cool bar widgets
549565
int i = 0;
@@ -668,7 +684,7 @@ static void CreateListView(Window* pWindow)
668684
}
669685
}
670686

671-
void CabinetEntry (UNUSED long argument)
687+
void CabinetEntry (long argument)
672688
{
673689
// create ourself a window:
674690
int xPos = (GetScreenSizeX() - CABINET_WIDTH) / 2;
@@ -684,12 +700,23 @@ void CabinetEntry (UNUSED long argument)
684700

685701
pWindow->m_iconID = ICON_CABINET;
686702

687-
pWindow->m_data = MmAllocate(sizeof(CabData));
703+
CabData* pData = pWindow->m_data = MmAllocate(sizeof(CabData));
704+
if (!pData)
705+
{
706+
if (argument)
707+
MmFree((char*)argument);
708+
709+
SLogMsg("Cabinet data couldn't be allocated!!");
710+
DestroyWindow(pWindow);
711+
while (HandleMessages(pWindow));
712+
return;
713+
}
688714

689-
g_bUsingTableView = true;
715+
g_pDestCWD = NULL;
716+
if (argument)
717+
g_pDestCWD = (char*) argument;
690718

691-
// setup:
692-
//ShowWindow(pWindow);
719+
g_bUsingTableView = true;
693720

694721
// event loop:
695722
#if THREADING_ENABLED

0 commit comments

Comments
 (0)