-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
839775a
commit 6b9d018
Showing
10 changed files
with
544 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "EnvHelper.h" | ||
#include <iostream> | ||
#include <windows.h> | ||
#include <iostream> | ||
#include <string> | ||
|
||
EnvHelper::EnvHelper() | ||
{ | ||
this->_init_env(); | ||
} | ||
|
||
EnvHelper::~EnvHelper() | ||
{ | ||
|
||
} | ||
|
||
std::map<wstring, wstring> EnvHelper::get_env() const | ||
{ | ||
std::map<wstring, wstring> result = {}; | ||
for (const wstring& item : _vec_env) { | ||
if (item.empty()) { | ||
continue; | ||
} | ||
if (item[0] == '=') { | ||
continue; | ||
} | ||
std::vector<wstring> values = _split(item, L'='); | ||
if (values.empty()) | ||
{ | ||
continue; | ||
} | ||
result[values[0]] = values[1]; | ||
} | ||
return result; | ||
} | ||
|
||
bool EnvHelper::_init_env() | ||
{ | ||
LPWCH envStrings = GetEnvironmentStringsW(); | ||
if (envStrings == NULL) { | ||
return false; | ||
} | ||
|
||
// 遍历环境变量 | ||
LPWCH envVar = envStrings; | ||
while (*envVar) { | ||
// 从环境变量字符串中提取键和值 | ||
std::wcout << envVar << std::endl; | ||
|
||
// 移动到下一个环境变量 | ||
envVar += wcslen(envVar) + 1; | ||
wstring var = envVar; | ||
_vec_env.push_back(var); | ||
} | ||
|
||
// 释放环境变量字符串指针 | ||
FreeEnvironmentStringsW(envStrings); | ||
return true; | ||
} | ||
|
||
|
||
std::vector<wstring> EnvHelper::_split(const wstring& str, wchar_t delimiter) const { | ||
std::vector<wstring> tokens; | ||
size_t start = 0; | ||
size_t end = str.find(delimiter); | ||
|
||
while (end != wstring::npos) { | ||
tokens.push_back(str.substr(start, end - start)); | ||
start = end + 1; | ||
end = str.find(delimiter, start); | ||
} | ||
|
||
// 添加最后一个子串 | ||
tokens.push_back(str.substr(start)); | ||
return tokens; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
using std::wstring; | ||
using std::vector; | ||
|
||
class EnvHelper | ||
{ | ||
public: | ||
EnvHelper(); | ||
~EnvHelper(); | ||
|
||
EnvHelper& operator=(const EnvHelper& left) = delete; | ||
EnvHelper(const EnvHelper& left) = delete; | ||
std::map<wstring, wstring> get_env() const; | ||
|
||
private: | ||
bool _init_env(); | ||
std::vector<std::wstring> _split(const std::wstring& str, wchar_t delimiter) const; | ||
|
||
private: | ||
vector<wstring> _vec_env; | ||
|
||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "EnvTools.h" | ||
#include <QTableWidgetItem> | ||
|
||
EnvTools::EnvTools(QWidget* parent) | ||
: QWidget(parent) | ||
{ | ||
ui.setupUi(this); | ||
this->_init_ui(); | ||
} | ||
|
||
EnvTools::~EnvTools() | ||
{} | ||
|
||
void EnvTools::_init_ui() | ||
{ | ||
std::map<wstring, wstring> values = _env_helper.get_env(); | ||
|
||
int idx = 0; | ||
for (auto& item : values) { | ||
this->ui.tableWidget->insertRow(idx); | ||
this->ui.tableWidget->setItem(idx, 0, new QTableWidgetItem(QString::fromStdWString(item.first))); | ||
this->ui.tableWidget->setItem(idx, 1, new QTableWidgetItem(QString::fromStdWString(item.second))); | ||
idx++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <QtWidgets/QWidget> | ||
#include "ui_EnvTools.h" | ||
#include "EnvHelper.h" | ||
|
||
class EnvTools : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
EnvTools(QWidget* parent = nullptr); | ||
~EnvTools(); | ||
|
||
private: | ||
void _init_ui(); | ||
|
||
private: | ||
Ui::EnvToolsClass ui; | ||
EnvHelper _env_helper; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<RCC> | ||
<qresource prefix="EnvTools"> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>EnvToolsClass</class> | ||
<widget class="QWidget" name="EnvToolsClass"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>937</width> | ||
<height>622</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>EnvTools</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<property name="spacing"> | ||
<number>0</number> | ||
</property> | ||
<property name="leftMargin"> | ||
<number>10</number> | ||
</property> | ||
<property name="topMargin"> | ||
<number>10</number> | ||
</property> | ||
<property name="rightMargin"> | ||
<number>10</number> | ||
</property> | ||
<property name="bottomMargin"> | ||
<number>10</number> | ||
</property> | ||
<item> | ||
<widget class="QWidget" name="widget" native="true"> | ||
<layout class="QVBoxLayout" name="verticalLayout_5"> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout_4"> | ||
<item> | ||
<layout class="QVBoxLayout" name="verticalLayout_3"> | ||
<item> | ||
<widget class="QLabel" name="label_3"> | ||
<property name="text"> | ||
<string>Other:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QTableWidget" name="tableWidget"> | ||
<attribute name="horizontalHeaderStretchLastSection"> | ||
<bool>true</bool> | ||
</attribute> | ||
<attribute name="verticalHeaderStretchLastSection"> | ||
<bool>true</bool> | ||
</attribute> | ||
<column> | ||
<property name="text"> | ||
<string>Name</string> | ||
</property> | ||
</column> | ||
<column> | ||
<property name="text"> | ||
<string>Value</string> | ||
</property> | ||
</column> | ||
</widget> | ||
</item> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<spacer name="horizontalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>40</width> | ||
<height>20</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="pushButton"> | ||
<property name="text"> | ||
<string>Add</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="pushButton_3"> | ||
<property name="text"> | ||
<string>Del</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<layout class="QVBoxLayout" name="verticalLayout_4"> | ||
<item> | ||
<layout class="QVBoxLayout" name="verticalLayout_2"> | ||
<item> | ||
<widget class="QLabel" name="label"> | ||
<property name="text"> | ||
<string>PATH evn:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QListWidget" name="listWidget"/> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout_2"> | ||
<item> | ||
<spacer name="horizontalSpacer_2"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>40</width> | ||
<height>20</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="pushButton_4"> | ||
<property name="text"> | ||
<string>Add</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="pushButton_5"> | ||
<property name="text"> | ||
<string>Del</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
<item> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="text"> | ||
<string>Tips: To apply the environment variable changes, you need to restart Explorer.</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer name="horizontalSpacer_3"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>40</width> | ||
<height>20</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="pushButton_2"> | ||
<property name="text"> | ||
<string>重启explorer</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<layoutdefault spacing="6" margin="11"/> | ||
<resources> | ||
<include location="EnvTools.qrc"/> | ||
</resources> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.32602.291 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "evn_tools", "evn_tools.vcxproj", "{9E8A8CE2-EC9C-4041-8C4A-4D17ED31A1DE}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Release|x64 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9E8A8CE2-EC9C-4041-8C4A-4D17ED31A1DE}.Debug|x64.ActiveCfg = Debug|x64 | ||
{9E8A8CE2-EC9C-4041-8C4A-4D17ED31A1DE}.Debug|x64.Build.0 = Debug|x64 | ||
{9E8A8CE2-EC9C-4041-8C4A-4D17ED31A1DE}.Release|x64.ActiveCfg = Release|x64 | ||
{9E8A8CE2-EC9C-4041-8C4A-4D17ED31A1DE}.Release|x64.Build.0 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {F1743090-610E-44E3-AD30-99699CD063BB} | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.