Skip to content

Commit

Permalink
v10.0; see readme.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Wittenberg committed Apr 6, 2018
1 parent b25c342 commit f24f776
Show file tree
Hide file tree
Showing 33 changed files with 3,756 additions and 976 deletions.
121 changes: 121 additions & 0 deletions src/BagOValues.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/********************************************************************
BagOValues.h
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
********************************************************************/

#include <map>
#include <vector>
#include <algorithm>

#include "spinlock.h"

using namespace std;

template <class TValue>
class BagOValues
{
typedef pair<wstring, TValue> TPair;
typedef vector<TPair> TVector;
typedef typename TVector::const_iterator TItr;

SpinLock m_spinlock;
TVector m_Values;
wstring m_lastStr;
TItr m_LastItr;

public:
BagOValues()
{
}

// copies the value, but doesn't assume any memory mangement needs be done
void Add(wstring key, TValue value)
{
this->m_spinlock.Lock();
wstring lowered;
lowered.resize(key.size());
transform(key.begin(), key.end(), lowered.begin(), ::tolower);
m_Values.insert(m_Values.end(), make_pair(lowered, value));

m_lastStr.resize(0); // clear this after new data added
this->m_spinlock.Unlock();
}

void Sort()
{
this->m_spinlock.Lock();
sort(m_Values.begin(), m_Values.end());
this->m_spinlock.Unlock();
}

// Retrieve with fPrefix = true means return values for the tree at the point of the query matched;
// we must consume the whole query for anything to be returned
// fPrefix = false means that we only return values when an entire key matches and we match substrings of the query
//
// NOTE: returns a newly allocated vector; must delete it
vector<TValue> *Retrieve(const wstring& query, bool fPrefix = true, unsigned maxResults = ULONG_MAX)
{
wstring lowered;
lowered.resize(query.size());
transform(query.begin(), query.end(), lowered.begin(), ::tolower);

vector<TValue> *results = NULL;
TValue val = TValue();
TPair laspair = make_pair(lowered, val);

this->m_spinlock.Lock();

// if last saved string/iterator is a prefix of the new string, start there
TVector::const_iterator itr;
if (m_lastStr.size() != 0 && lowered.compare(0, m_lastStr.size(), m_lastStr) == 0)
itr = m_LastItr;
else
{
itr = lower_bound(m_Values.begin(), m_Values.end(), laspair, CompareFirst);

m_lastStr = lowered;
m_LastItr = itr;
}

for (; itr != m_Values.end(); itr++)
{
const wstring& key = itr->first;
int cmp = key.compare(0, lowered.size(), lowered);
if (cmp == 0)
{
if (!fPrefix && key.size() != lowered.size())
{
// need exact match (not just prefix); skip
continue;
}

if (results == NULL)
results = new vector<TValue>();

if (results->size() >= maxResults)
break;

results->insert(results->end(), itr->second);
}
else if (cmp > 0)
{
// iterated past the strings which match on the prefix
break;
}
}

this->m_spinlock.Unlock();
return results;
}

private:
static bool CompareFirst(const TPair& a, const TPair& b)
{
return a.first < b.first;
}
};

6 changes: 6 additions & 0 deletions src/Winfile.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,16 @@
<ClInclude Include="dbg.h" />
<ClInclude Include="fmifs.h" />
<ClInclude Include="lfn.h" />
<ClInclude Include="BagOValues.h" />
<ClInclude Include="mpr.h" />
<ClInclude Include="numfmt.h" />
<ClInclude Include="spinlock.h" />
<ClInclude Include="suggest.h" />
<ClInclude Include="treectl.h" />
<ClInclude Include="wfcopy.h" />
<ClInclude Include="wfdlgs.h" />
<ClInclude Include="wfdocb.h" />
<ClInclude Include="wfdrop.h" />
<ClInclude Include="wfext.h" />
<ClInclude Include="wfexti.h" />
<ClInclude Include="wfgwl.h" />
Expand Down Expand Up @@ -266,8 +270,10 @@
<ClCompile Include="wfdlgs3.c" />
<ClCompile Include="wfdos.c" />
<ClCompile Include="wfdrives.c" />
<ClCompile Include="wfdrop.c" />
<ClCompile Include="wfext.c" />
<ClCompile Include="wffile.c" />
<ClCompile Include="wfgoto.cpp" />
<ClCompile Include="wfinfo.c" />
<ClCompile Include="wfinit.c" />
<ClCompile Include="wfmem.c" />
Expand Down
31 changes: 27 additions & 4 deletions src/lfn.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,28 @@ WFFindFirst(
// and ORDINARY files too.
//

dwAttrFilter |= ATTR_ARCHIVE | ATTR_READONLY | ATTR_NORMAL |
ATTR_TEMPORARY | ATTR_COMPRESSED | ATTR_NOT_INDEXED;
lpFind->hFindFile = FindFirstFile(lpName, &lpFind->fd);
PVOID oldValue;
Wow64DisableWow64FsRedirection(&oldValue);

if ((dwAttrFilter & ~(ATTR_DIR | ATTR_HS)) == 0)
{
// directories only (hidden or not)
lpFind->hFindFile = FindFirstFileEx(lpName, FindExInfoStandard, &lpFind->fd, FindExSearchLimitToDirectories, NULL, 0);
}
else
{
// normal case: directories and files
lpFind->hFindFile = FindFirstFile(lpName, &lpFind->fd);
}

// add in attr_* which we want to include in the match even though the caller didn't request them.
dwAttrFilter |= ATTR_ARCHIVE | ATTR_READONLY | ATTR_NORMAL | ATTR_REPARSE_POINT |
ATTR_TEMPORARY | ATTR_COMPRESSED | ATTR_NOT_INDEXED;

lpFind->fd.dwFileAttributes &= ATTR_USED;


Wow64RevertWow64FsRedirection(oldValue);

//
// Keep track of length
//
Expand Down Expand Up @@ -93,6 +109,9 @@ WFFindFirst(
BOOL
WFFindNext(LPLFNDTA lpFind)
{
PVOID oldValue;
Wow64DisableWow64FsRedirection(&oldValue);

while (FindNextFile(lpFind->hFindFile, &lpFind->fd)) {

lpFind->fd.dwFileAttributes &= ATTR_USED;
Expand Down Expand Up @@ -120,9 +139,13 @@ WFFindNext(LPLFNDTA lpFind)
lstrcpy(lpFind->fd.cFileName, lpFind->fd.cAlternateFileName);
}

Wow64RevertWow64FsRedirection(oldValue);

return TRUE;
}

Wow64RevertWow64FsRedirection(oldValue);

lpFind->err = GetLastError();
return(FALSE);
}
Expand Down
64 changes: 51 additions & 13 deletions src/res.rc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ BEGIN
VK_ESCAPE, IDM_ESCAPE, NOINVERT, VIRTKEY
VK_RETURN, IDM_OPEN, NOINVERT, VIRTKEY
VK_RETURN, IDM_OPEN, NOINVERT, VIRTKEY, SHIFT
VK_F12, IDM_EDIT, VIRTKEY
VK_F7, IDM_MOVE, VIRTKEY
VK_F8, IDM_COPY, VIRTKEY
VK_F9, IDM_COPYTOCLIPBOARD, VIRTKEY
Expand All @@ -53,31 +54,46 @@ BEGIN
VK_SUBTRACT,IDM_COLLAPSE, NOINVERT, VIRTKEY

VK_RETURN, IDM_ATTRIBS, NOINVERT, VIRTKEY, ALT
VK_F2, IDM_DRIVELISTJUMP, NOINVERT, VIRTKEY
VK_F2, IDM_RENAME, NOINVERT, VIRTKEY
"^x", IDM_CUTTOCLIPBOARD, NOINVERT
"^c", IDM_COPYTOCLIPBOARD, NOINVERT
"^v", IDM_PASTE, NOINVERT
"^k", IDM_STARTCMDSHELL, NOINVERT
"^g", IDM_GOTODIR, NOINVERT
"^f", IDM_SEARCH, NOINVERT
VK_LEFT, IDM_HISTORYBACK, NOINVERT, VIRTKEY, ALT
VK_RIGHT, IDM_HISTORYFWD, NOINVERT, VIRTKEY, ALT
VK_BROWSER_BACK, IDM_HISTORYBACK, NOINVERT, VIRTKEY
VK_BROWSER_FORWARD, IDM_HISTORYFWD, NOINVERT, VIRTKEY
END

FRAMEMENU MENU PRELOAD
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Open\tEnter", IDM_OPEN
MENUITEM "Edit\tF12", IDM_EDIT
MENUITEM "&Move...\tF7", IDM_MOVE
MENUITEM "&Copy...\tF8", IDM_COPY
MENUITEM "Copy to Clip&board...\tF9", IDM_COPYTOCLIPBOARD
MENUITEM "Copy to Clip&board\tCtrl+C", IDM_COPYTOCLIPBOARD
MENUITEM "Cut to Clipboard\tCtrl+X", IDM_CUTTOCLIPBOARD
MENUITEM "&Paste\tCtrl+V", IDM_PASTE
MENUITEM "&Delete...\tDel", IDM_DELETE
MENUITEM "Re&name...", IDM_RENAME
MENUITEM "Re&name...\tF2", IDM_RENAME
MENUITEM "Proper&ties...\tAlt+Enter",IDM_ATTRIBS
MENUITEM SEPARATOR
MENUITEM "Compre&ss...", IDM_COMPRESS
MENUITEM "&Uncompress...", IDM_UNCOMPRESS
MENUITEM SEPARATOR
MENUITEM "&Run...", IDM_RUN
MENUITEM "&Print...", IDM_PRINT
MENUITEM "Pr&int...", IDM_PRINT
MENUITEM "&Associate...", IDM_ASSOCIATE
MENUITEM SEPARATOR
MENUITEM "Cr&eate Directory...", IDM_MAKEDIR
MENUITEM "Searc&h...", IDM_SEARCH
MENUITEM "Searc&h...\tCtrl+F", IDM_SEARCH
MENUITEM "Select &Files...", IDM_SELECT
MENUITEM "Start Cmd Shel&l...", IDM_STARTCMDSHELL
MENUITEM "&Goto Directory...\tCtrl+G", IDM_GOTODIR
MENUITEM SEPARATOR
MENUITEM "E&xit", IDM_EXIT
END
Expand Down Expand Up @@ -110,15 +126,12 @@ BEGIN
MENUITEM "&Name", IDM_VNAME,
MENUITEM "&All File Details", IDM_VDETAILS, CHECKED
MENUITEM "&Partial Details...", IDM_VOTHER
#ifdef PROGMAN
MENUITEM SEPARATOR
MENUITEM "&Icon View" IDM_VICON
#endif
MENUITEM SEPARATOR
MENUITEM "&Sort by Name", IDM_BYNAME
MENUITEM "Sort &by Type", IDM_BYTYPE
MENUITEM "Sort by Si&ze", IDM_BYSIZE
MENUITEM "Sort by &Date", IDM_BYDATE
MENUITEM "Sort &forward Date", IDM_BYFDATE
MENUITEM SEPARATOR
MENUITEM "By File &Type...", IDM_VINCLUDE
END
Expand Down Expand Up @@ -165,6 +178,28 @@ BEGIN

END

CTXMENU MENU PRELOAD
BEGIN
POPUP "Dummy Popup"
BEGIN
MENUITEM "&New Window\ton Selection", IDM_NEWWINDOW
MENUITEM "&Open\tEnter", IDM_OPEN
MENUITEM "Edit\tF12", IDM_EDIT
MENUITEM "&Move...\tF7", IDM_MOVE
MENUITEM "&Copy...\tF8", IDM_COPY
MENUITEM "Copy to Clip&board\tCtrl+C", IDM_COPYTOCLIPBOARD
MENUITEM "Cut to Clipboard\tCtrl+X", IDM_CUTTOCLIPBOARD
MENUITEM "&Paste\tCtrl+V", IDM_PASTE
MENUITEM "&Delete...\tDel", IDM_DELETE
MENUITEM "Re&name...\tF2", IDM_RENAME
MENUITEM "Proper&ties...\tAlt+Enter",IDM_ATTRIBS
MENUITEM "&Run...", IDM_RUN
MENUITEM "Start Cmd She&ll...", IDM_STARTCMDSHELL
MENUITEM "&Goto Directory...", IDM_GOTODIR
MENUITEM "About", IDM_ABOUT
END
END


/* 0....5....1....56...2....5....3.2..5....4....5....5....6....5....7....5....8....5....9....5....0....5....1....5....2....5..8 */
STRINGTABLE DISCARDABLE PRELOAD
Expand Down Expand Up @@ -210,7 +245,7 @@ BEGIN
Labels cannot contain the following characters:\n[space] * ? / \\ | . , ; : + = [ ] ( ) & ^ < > "" "

IDS_SEARCHNOMATCHES "No matching files were found."
IDS_SEARCHREFRESH "The contents of this drive have changed. Do you want to update the Search Results window?"
IDS_SEARCHREFRESH "The contents of this drive have changed. Do you want to retry the Search?"
IDS_LABELACCESSDENIED "You must be logged onto this workstation as an administrator to perform this operation on hard disks."

IDS_DRIVETEMP "Drive %c:%c"
Expand Down Expand Up @@ -329,7 +364,6 @@ JAPANEND

IDS_DESTFULL "The destination disk is full. Please insert another disk to continue."
IDS_WRITEPROTECTFILE "This is a system, hidden, or read-only file."
IDS_NOCOPYTOCLIP "File manager cannot copy multiple files or directories to the Clipboard.\n\nSelect a single file, and then try again."

IDS_COPYINGTITLE "Copying..."

Expand Down Expand Up @@ -544,9 +578,12 @@ END
STRINGTABLE LOADONCALL MOVEABLE DISCARDABLE
BEGIN
MH_MYITEMS+IDM_OPEN, "Opens selected item"
MH_MYITEMS+IDM_EDIT, "Edits selected item using notepad.exe"
MH_MYITEMS+IDM_MOVE, "Moves selected item"
MH_MYITEMS+IDM_COPY, "Copies files and directories"
MH_MYITEMS+IDM_COPYTOCLIPBOARD, "Copies a file to the clipboard"
MH_MYITEMS+IDM_COPYTOCLIPBOARD, "Copies one or more files to the clipboard"
MH_MYITEMS+IDM_CUTTOCLIPBOARD, "Cuts one or more files to the clipboard"
MH_MYITEMS+IDM_PASTE, "Paste file from clipboard to current directory"
MH_MYITEMS+IDM_COMPRESS, "Compresses a file or directory"
MH_MYITEMS+IDM_UNCOMPRESS, "Uncompresses a file or directory"
MH_MYITEMS+IDM_DELETE, "Deletes files and directories"
Expand Down Expand Up @@ -591,6 +628,7 @@ BEGIN
MH_MYITEMS+IDM_BYTYPE, "Sorts files by type"
MH_MYITEMS+IDM_BYSIZE, "Sorts files by size"
MH_MYITEMS+IDM_BYDATE, "Sorts files by date"
MH_MYITEMS+IDM_BYFDATE, "Sorts files by foward date"
MH_MYITEMS+IDM_VINCLUDE, "Shows files of a specified type"

MH_MYITEMS+IDM_CONFIRM, "Controls confirmation messages"
Expand Down Expand Up @@ -650,4 +688,4 @@ END

#include "common.ver"



Loading

0 comments on commit f24f776

Please sign in to comment.