Skip to content

Commit

Permalink
Allow user to open a single directory on the command line (#431)
Browse files Browse the repository at this point in the history
* Allow user to open a single directory on the command line

* Remove some blank lines that didn't seem warranted

---------

Co-authored-by: Malcolm <[email protected]>
Co-authored-by: Malcolm <[email protected]>
  • Loading branch information
3 people authored Mar 24, 2024
1 parent 1f6bb81 commit 21195b6
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 69 deletions.
158 changes: 110 additions & 48 deletions src/wfinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,9 @@ CheckDirExists(


BOOL
CreateSavedWindows()
CreateSavedWindows(
LPCWSTR pszInitialDir
)
{
WCHAR buf[2*MAXPATHLEN+7*7], key[10];
WINDOW win;
Expand All @@ -781,56 +783,90 @@ CreateSavedWindows()
nDirNum = 1;
iNumTrees = 0;

do {
wsprintf(key, szDirKeyFormat, nDirNum++);
if (pszInitialDir == NULL)
{
do
{
wsprintf(key, szDirKeyFormat, nDirNum++);

GetPrivateProfileString(szSettings, key, szNULL, buf, COUNTOF(buf), szTheINIFile);

if (*buf)
{
GetSavedWindow(buf, &win);

//
// clean off some junk so we
// can do this test
//
lstrcpy(szDir, win.szDir);
StripFilespec(szDir);
StripBackslash(szDir);

if (!CheckDirExists(szDir)) {
continue;
}

GetPrivateProfileString(szSettings, key, szNULL, buf, COUNTOF(buf), szTheINIFile);
dwNewView = win.dwView;
dwNewSort = win.dwSort;
dwNewAttribs = win.dwAttribs;

if (*buf) {
hwnd = CreateTreeWindow(win.szDir,
win.rc.left,
win.rc.top,
win.rc.right - win.rc.left,
win.rc.bottom - win.rc.top,
win.nSplit);

GetSavedWindow(buf, &win);
if (!hwnd) {
continue;
}

//
// clean off some junk so we
// can do this test
//
lstrcpy(szDir, win.szDir);
StripFilespec(szDir);
StripBackslash(szDir);

if (!CheckDirExists(szDir))
continue;

dwNewView = win.dwView;
dwNewSort = win.dwSort;
dwNewAttribs = win.dwAttribs;

hwnd = CreateTreeWindow(win.szDir,
win.rc.left,
win.rc.top,
win.rc.right - win.rc.left,
win.rc.bottom - win.rc.top,
win.nSplit);

if (!hwnd) {
continue;
iNumTrees++;

//
// keep track of this for now...
//
if (IsIconic(hwnd)) {
SetWindowPos(hwnd, NULL, win.pt.x, win.pt.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}

ShowWindow(hwnd, win.sw);
}

iNumTrees++;
} while (*buf);
}

//
// keep track of this for now...
//
if (IsIconic(hwnd))
SetWindowPos(hwnd, NULL, win.pt.x, win.pt.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
//
// If the user requested to open the program with a specific directory,
// open it
//

ShowWindow(hwnd, win.sw);
}
if (pszInitialDir != NULL){

lstrcpy(buf, pszInitialDir);
AddBackslash(buf);
lstrcat(buf, szStarDotStar);

//
// default to split window
//
hwnd = CreateTreeWindow(buf, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, -1);

} while (*buf);
if (!hwnd)
return FALSE;

//
// Default to maximized since the user requested to open a single
// directory
//
ShowWindow(hwnd, SW_MAXIMIZE);

iNumTrees++;
}

//
// if nothing was saved create a tree for the current drive
// if nothing was saved or specified, create a tree for the current drive
//
if (!iNumTrees) {

Expand Down Expand Up @@ -984,6 +1020,7 @@ InitFileManager(
HANDLE hThread;
DWORD dwRetval;
DWORD dwExStyle = 0L;
LPWSTR pszInitialDir = NULL;

hThread = GetCurrentThread();

Expand All @@ -1008,9 +1045,6 @@ InitFileManager(
//
hAppInstance = hInstance;

if (*lpCmdLine)
nCmdShow = SW_SHOWMINNOACTIVE;

// setup ini file location
lstrcpy(szTheINIFile, szBaseINIFile);
dwRetval = GetEnvironmentVariable(TEXT("APPDATA"), szBuffer, MAXPATHLEN);
Expand Down Expand Up @@ -1073,19 +1107,46 @@ JAPANEND
//
GetCurrentDirectory(COUNTOF(szOriginalDirPath), szOriginalDirPath);

if (*lpCmdLine) {
if (*lpCmdLine)
{
LPWSTR lpArgs;

//
// Note this isn't just finding the next argument, it's NULL
// terminating lpCmdLine at the point of the next argument
//
lpArgs = pszNextComponent(lpCmdLine);
lpCmdLine = pszRemoveSurroundingQuotes(lpCmdLine);

if (dwRetval = ExecProgram(lpCmdLine, pszNextComponent(lpCmdLine), NULL, FALSE, FALSE))
MyMessageBox(NULL, IDS_EXECERRTITLE, dwRetval, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
if (WFIsDir(lpCmdLine))
{
pszInitialDir = lpCmdLine;
}
else
{
nCmdShow = SW_SHOWMINNOACTIVE;

dwRetval = ExecProgram(lpCmdLine, lpArgs, NULL, FALSE, FALSE);
if (dwRetval != 0)
{
MyMessageBox(NULL, IDS_EXECERRTITLE, dwRetval, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
}
}
}

//
// Read WINFILE.INI and set the appropriate variables.
//
GetSettings();

//
// If the user specified an initial directory on the command line, that
// directory will be opened, and save settings is disabled by default.
//
if (pszInitialDir != NULL) {
bSaveSettings = FALSE;
}

dwExStyle = MainWindowExStyle();

dyBorder = GetSystemMetrics(SM_CYBORDER);
Expand Down Expand Up @@ -1456,8 +1517,9 @@ JAPANEND
//
if (nCmdShow == SW_SHOW || nCmdShow == SW_SHOWNORMAL &&
win.sw != SW_SHOWMINIMIZED)

{
nCmdShow = win.sw;
}

ShowWindow(hwndFrame, nCmdShow);

Expand Down Expand Up @@ -1512,7 +1574,7 @@ JAPANEND
InitMenus();


if (!CreateSavedWindows()) {
if (!CreateSavedWindows(pszInitialDir)) {
return FALSE;
}

Expand Down
27 changes: 26 additions & 1 deletion src/wfutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pszNextComponent(
if ((*p == L' ' || *p == L'\t') && !bInQuotes)
break;

if (*p == L'\"')
if (*p == CHAR_DQUOTE)
bInQuotes = !bInQuotes;

p++;
Expand All @@ -92,6 +92,31 @@ pszNextComponent(
return p;
}

// If a string starts and ends with a quote, truncate the ending quote and
// return a pointer to the new string start. Note that parsing such as
// pszNextComponent above support quotes in the middle of strings, which
// this function makes no attempt to remove.
LPWSTR
pszRemoveSurroundingQuotes(
LPWSTR p
)
{
if (*p == CHAR_DQUOTE) {
size_t len;

len = wcslen(p);

// Length needs to be at least 2 to ensure there are 2 quotes rather
// than counting the same quote twice
if (len > 1 && p[len - 1] == CHAR_DQUOTE) {
p[len - 1] = '\0';
p++;
}
}

return p;
}


// Set the status bar text for a given pane

Expand Down
41 changes: 21 additions & 20 deletions src/winfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ VOID ExtSelItemsInvalidate();
// WFUTIL.C

LPWSTR pszNextComponent(LPWSTR pszCmdLine);
LPWSTR pszRemoveSurroundingQuotes(LPWSTR p);
VOID cdecl SetStatusText(INT nPane, UINT nFormat, LPCTSTR szFormat, ...);
VOID RefreshWindow(HWND hwndActive, BOOL bUpdateDriveList, BOOL bFlushCache);
BOOL IsLastWindow(VOID);
Expand Down Expand Up @@ -527,7 +528,7 @@ VOID InitDriveBitmaps(VOID);
VOID InitExtensions(VOID);
VOID FreeFileManager(VOID);
VOID DeleteBitmaps(VOID);
BOOL CreateSavedWindows(VOID);
BOOL CreateSavedWindows(LPCWSTR pszInitialDir);
VOID InitExtensions(VOID);
INT GetDriveOffset(DRIVE drive);
VOID InitMenus(VOID);
Expand Down Expand Up @@ -1211,30 +1212,30 @@ JAPANBEGIN
Extern BOOL bJapan EQ( FALSE );
JAPANEND

Extern BOOL bMinOnRun EQ( FALSE );
Extern BOOL bIndexOnLaunch EQ( TRUE );
Extern BOOL bStatusBar EQ( TRUE );
Extern BOOL bMinOnRun EQ( FALSE );
Extern BOOL bIndexOnLaunch EQ( TRUE );
Extern BOOL bStatusBar EQ( TRUE );

Extern BOOL bDriveBar EQ( TRUE );
Extern BOOL bToolbar EQ( TRUE );
Extern BOOL bNewWinOnConnect EQ( TRUE );
Extern BOOL bDisableVisualStyles EQ( FALSE );
Extern BOOL bMirrorContent EQ( FALSE );

Extern BOOL bExitWindows EQ( FALSE );
Extern BOOL bConfirmDelete EQ( TRUE );
Extern BOOL bConfirmSubDel EQ( TRUE );
Extern BOOL bConfirmReplace EQ( TRUE );
Extern BOOL bConfirmMouse EQ( TRUE );
Extern BOOL bConfirmFormat EQ( TRUE );
Extern BOOL bConfirmReadOnly EQ( TRUE );

Extern BOOL bSaveSettings EQ( TRUE );
Extern BOOL bScrollOnExpand EQ( TRUE );

Extern BOOL bConnectable EQ( FALSE );
Extern INT iShowSourceBitmaps EQ( 1 );
Extern BOOL bFSCTimerSet EQ( FALSE );
Extern BOOL bMirrorContent EQ( FALSE );

Extern BOOL bExitWindows EQ( FALSE );
Extern BOOL bConfirmDelete EQ( TRUE );
Extern BOOL bConfirmSubDel EQ( TRUE );
Extern BOOL bConfirmReplace EQ( TRUE );
Extern BOOL bConfirmMouse EQ( TRUE );
Extern BOOL bConfirmFormat EQ( TRUE );
Extern BOOL bConfirmReadOnly EQ( TRUE );

Extern BOOL bSaveSettings EQ( TRUE );
Extern BOOL bScrollOnExpand EQ( TRUE );

Extern BOOL bConnectable EQ( FALSE );
Extern INT iShowSourceBitmaps EQ( 1 );
Extern BOOL bFSCTimerSet EQ( FALSE );

Extern TCHAR chFirstDrive; // 'A' or 'a'

Expand Down

0 comments on commit 21195b6

Please sign in to comment.