This repository was archived by the owner on Aug 12, 2020. It is now read-only.
forked from epsylon3/odbgscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmru.cpp
More file actions
120 lines (98 loc) · 1.98 KB
/
mru.cpp
File metadata and controls
120 lines (98 loc) · 1.98 KB
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
#include "mru.h"
#include "version.h"
#include <shlwapi.h>
#include <algorithm>
#include <sstream>
MRU::MRU(unsigned int max_size) : max_size(max_size)
{
items.reserve(max_size);
}
unsigned int MRU::size() const
{
return items.size();
}
bool MRU::load()
{
wchar_t buf[MAX_PATH];
clear();
for(size_t i = 0; i < max_size; i++)
{
std::wostringstream key;
key << "MRU" << i + 1;
buf[0] = L'\0';
Getfromini(NULL, PLUGIN_NAME, const_cast<wchar_t*>(key.str().c_str()), L"%260s", buf);
buf[_countof(buf) - 1] = L'\0';
if(wcslen(buf) > 0 && PathFileExists(buf))
{
items.push_back(buf);
}
}
return true;
}
bool MRU::save() const
{
for(size_t i = 0; i < max_size; i++)
{
std::wostringstream key;
key << "MRU" << i + 1;
std::wstring val = get(i);
Writetoini(NULL, PLUGIN_NAME, const_cast<wchar_t*>(key.str().c_str()), L"%s", val.c_str());
}
return true;
}
void MRU::clear()
{
items.clear();
}
std::wstring MRU::get(int i) const
{
std::wstring val;
if(i >= 0 && i < items.size())
{
val = items[i];
}
return val;
}
bool MRU::add(const std::wstring& file)
{
std::vector<std::wstring>::iterator it = std::find(items.begin(), items.end(), file);
if(it != items.end())
{
if(it != items.begin())
{
std::swap(items.front(), *it);
}
}
else
{
items.insert(items.begin(), file);
if(items.size() >= max_size)
{
items.resize(max_size);
}
}
return true;
}
bool MRU::remove(const std::wstring& file)
{
std::vector<std::wstring>::iterator it = find(items.begin(), items.end(), file);
if(it != items.end())
{
items.erase(it);
return true;
}
return false;
}
OllyMenu MRU::build_menu(MENUFUNC* handler) const
{
OllyMenu menu;
for(size_t i = 0; i < items.size(); i++)
{
std::wstring file = items[i];
if(!file.empty() && PathFileExists(file.c_str()))
{
menu.add(file, L"", K_NONE, handler, i);
}
}
return menu;
}