Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 91dbf00

Browse files
Hermann Schinaglschinagl
authored andcommitted
Persist non open UNC drives
1 parent ba6b5f7 commit 91dbf00

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

src/wfdlgs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ SaveWindows(HWND hwndMain)
116116
szPath,
117117
aDriveInfo[drive].szRoot,
118118
drive - OFFSET_UNC);
119+
120+
aDriveInfo[drive].bDirtyPersist = TRUE;
119121
}
120122

121123
// the dir is an ANSI string (?)
@@ -136,6 +138,8 @@ SaveWindows(HWND hwndMain)
136138
goto DO_AGAIN;
137139
}
138140

141+
SaveUNCDrives();
142+
139143
// Save CachedPath and GotoCachePunctuation
140144
WritePrivateProfileString(szSettings, szCachedPath, szCachedPathIni, szTheINIFile);
141145
WritePrivateProfileString(szSettings, szGotoCachePunctuation, szPunctuation, szTheINIFile);

src/wfinit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ CreateSavedWindows()
876876

877877
} while (*buf);
878878

879+
LoadUNCDrives();
880+
879881
//
880882
// if nothing was saved create a tree for the current drive
881883
//

src/wfutil.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,10 +1646,52 @@ DRIVE FindUNCDrive(LPCTSTR path, PDWORD pdwFreeDriveSlot)
16461646
return 0;
16471647
}
16481648

1649+
VOID SaveUNCDrives()
1650+
{
1651+
TCHAR szUNCBuf[MAXPATHLEN];
1652+
for (DWORD dwDriveIndex = OFFSET_UNC; dwDriveIndex < MAX_DRIVES; ++dwDriveIndex) {
1653+
1654+
TCHAR szUNCKey[MAXPATHLEN];
1655+
wsprintf(szUNCKey, szUNCKeyFormat, dwDriveIndex - OFFSET_UNC);
1656+
1657+
if (aDriveInfo[dwDriveIndex].bDirtyPersist == FALSE && aDriveInfo[dwDriveIndex].szRoot[0])
1658+
{
1659+
// For UNC path we need to save the name of the root and the drive id too
1660+
wsprintf(szUNCBuf, TEXT("%s"),
1661+
aDriveInfo[dwDriveIndex].szRoot);
1662+
1663+
WritePrivateProfileString(szSettings, szUNCKey, szUNCBuf, szTheINIFile);
1664+
} else {
1665+
WritePrivateProfileString(szSettings, szUNCKey, NULL, szTheINIFile);
1666+
aDriveInfo[dwDriveIndex].bDirtyPersist = FALSE;
1667+
}
1668+
1669+
}
1670+
}
1671+
1672+
VOID LoadUNCDrives()
1673+
{
1674+
TCHAR szUNCBuf[MAXPATHLEN];
1675+
for (DWORD dwDriveIndex = OFFSET_UNC; dwDriveIndex < MAX_DRIVES; ++dwDriveIndex) {
1676+
1677+
TCHAR szUNCKey[MAXPATHLEN];
1678+
wsprintf(szUNCKey, szUNCKeyFormat, dwDriveIndex - OFFSET_UNC);
1679+
1680+
GetPrivateProfileString(szSettings, szUNCKey, szNULL, szUNCBuf, COUNTOF(szUNCBuf), szTheINIFile);
1681+
if (szUNCBuf[0])
1682+
SetUNCDrive(szUNCBuf, dwDriveIndex);
1683+
}
1684+
}
1685+
16491686
VOID SetUNCDrive(LPTSTR path, DWORD aFreeDriveSlot)
16501687
{
16511688
lstrcpy(aDriveInfo[aFreeDriveSlot].szRoot, path);
16521689
lstrcpy(aDriveInfo[aFreeDriveSlot].szRootBackslash, path);
1690+
1691+
// Force drive to be Network drive
1692+
aDriveInfo[aFreeDriveSlot].uType = DRIVE_REMOTE;
1693+
aDriveInfo[aFreeDriveSlot].iOffset = GetDriveOffset(aFreeDriveSlot);
1694+
16531695
AddBackslash(aDriveInfo[aFreeDriveSlot].szRootBackslash);
16541696
}
16551697

src/winfile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ DRIVE RemoveUNCDrive(LPCTSTR path);
443443
DRIVE FindUNCDrive(LPCTSTR path, PDWORD pdwFreeDriveSlot);
444444
BOOL FindUNCLoop(LPCTSTR path);
445445
VOID SetUNCDrive(LPTSTR path, DWORD aFreeDriveSlot);
446+
VOID SaveUNCDrives();
447+
VOID LoadUNCDrives();
446448

447449
// WFDIR.C
448450

@@ -956,6 +958,7 @@ typedef struct _DRIVE_INFO {
956958

957959
TCHAR szRoot[MAXPATHLEN];
958960
TCHAR szRootBackslash[MAXPATHLEN];
961+
BOOL bDirtyPersist;
959962
} DRIVEINFO, *PDRIVEINFO;
960963

961964
#define SC_SPLIT 100
@@ -1230,6 +1233,7 @@ Extern TCHAR szChangeNotifyTime[] EQ( TEXT("ChangeNotifyTime") );
12301233
Extern UINT uChangeNotifyTime EQ( 3000 );
12311234

12321235
Extern TCHAR szDirKeyFormat[] EQ( TEXT("dir%d") );
1236+
Extern TCHAR szUNCKeyFormat[] EQ(TEXT("unc%d"));
12331237
Extern TCHAR szWindow[] EQ( TEXT("Window") );
12341238
Extern TCHAR szWindows[] EQ( TEXT("Windows") );
12351239

0 commit comments

Comments
 (0)