Skip to content

Commit ce25c84

Browse files
authored
Add files via upload
1 parent 9588222 commit ce25c84

21 files changed

+77452
-0
lines changed

CMakeLists.txt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(mysystem VERSION 0.1 LANGUAGES CXX)
4+
5+
set(CMAKE_AUTOUIC ON)
6+
set(CMAKE_AUTOMOC ON)
7+
set(CMAKE_AUTORCC ON)
8+
9+
set(CMAKE_CXX_STANDARD 17)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
12+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
13+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
14+
15+
set(PROJECT_SOURCES
16+
main.cpp
17+
widget.cpp
18+
widget.h
19+
widget.ui
20+
)
21+
22+
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
23+
qt_add_executable(mysystem
24+
MANUAL_FINALIZATION
25+
${PROJECT_SOURCES}
26+
scan.h scan.cpp
27+
mystack.h mystack.cpp
28+
treenode.h treenode.cpp
29+
sqlcreator.h sqlcreator.cpp
30+
filesimulator.h filesimulator.cpp
31+
directorysimulator.h directorysimulator.cpp
32+
33+
)
34+
# Define target properties for Android with Qt 6 as:
35+
# set_property(TARGET mysystem APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
36+
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
37+
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
38+
else()
39+
if(ANDROID)
40+
add_library(mysystem SHARED
41+
${PROJECT_SOURCES}
42+
)
43+
# Define properties for Android with Qt 5 after find_package() calls as:
44+
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
45+
else()
46+
add_executable(mysystem
47+
${PROJECT_SOURCES}
48+
)
49+
endif()
50+
endif()
51+
52+
target_link_libraries(mysystem PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
53+
54+
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
55+
# If you are developing for iOS or macOS you should consider setting an
56+
# explicit, fixed bundle identifier manually though.
57+
if(${QT_VERSION} VERSION_LESS 6.1.0)
58+
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.mysystem)
59+
endif()
60+
set_target_properties(mysystem PROPERTIES
61+
${BUNDLE_ID_OPTION}
62+
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
63+
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
64+
MACOSX_BUNDLE TRUE
65+
WIN32_EXECUTABLE TRUE
66+
)
67+
68+
include(GNUInstallDirs)
69+
install(TARGETS mysystem
70+
BUNDLE DESTINATION .
71+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
72+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
73+
)
74+
75+
if(QT_VERSION_MAJOR EQUAL 6)
76+
qt_finalize_executable(mysystem)
77+
endif()

CMakeLists.txt.user

Lines changed: 621 additions & 0 deletions
Large diffs are not rendered by default.

directorysimulator.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include "DirectorySimulator.h"
2+
3+
DirectorySimulator::DirectorySimulator(const std::string& filename,TreeNode *currentnode) {
4+
std::ifstream file(filename);
5+
std::string line;
6+
this->node = currentnode;
7+
8+
while (std::getline(file, line) && line != "end of dirs") {
9+
if (line == "selected dirs") {
10+
while (std::getline(file, line) && line != "end of dirs") {
11+
std::istringstream iss(line);
12+
std::string token;
13+
14+
std::getline(iss, token, ',');
15+
std::string fullPath = token;
16+
17+
std::getline(iss, token, ',');
18+
char operation = token.empty() ? '\0' : token[0];
19+
20+
std::getline(iss, token, ',');
21+
std::string time = token;
22+
23+
std::getline(iss, token, ',');
24+
std::string size = token;
25+
26+
// 获取去掉最后一个文件的目录路径
27+
size_t lastSlashPos = fullPath.find_last_of("\\");
28+
std::string parentDirectory = (lastSlashPos != std::string::npos) ? fullPath.substr(0, lastSlashPos) : "";
29+
lastSlashPos = parentDirectory.find_last_of("\\");
30+
parentDirectory = (lastSlashPos != std::string::npos) ? parentDirectory.substr(0, lastSlashPos) : "";
31+
directoryOperations.push_back({fullPath,parentDirectory, operation, time, size});
32+
}
33+
}
34+
}
35+
}
36+
37+
void DirectorySimulator::executeDirectoryOperations(const char *filename) {
38+
std::ofstream outputFile(filename);
39+
if (!outputFile.is_open())
40+
{
41+
std::cerr << "Error: Unable to open the file for writing." << std::endl;
42+
return;
43+
}
44+
for (const auto& op : directoryOperations) {
45+
std::cout << "Operation: " << op.operation << " on directory: " << op.fullPath <<std::endl<<op.parentDirectory<< std::endl;
46+
// 执行目录操作的代码
47+
48+
TreeNode *panode = node->findDirectory(node,op.parentDirectory.c_str());
49+
TreeNode *nownode = node->findDirectory(node,op.fullPath.c_str());
50+
51+
if(nownode != nullptr)
52+
{
53+
outputFile << "Deleted Directory: " << nownode->path << " (" << nownode->name << ")" << std::endl;
54+
55+
if(panode->firstChild == nownode)
56+
{
57+
panode->firstChild = nownode->nextSibling;
58+
nownode->nextSibling = nullptr;
59+
nownode->printDeletedNodesToFile(outputFile);
60+
delete nownode;
61+
}
62+
else
63+
{
64+
TreeNode *p = panode->firstChild;
65+
while(p->nextSibling != nownode)
66+
{
67+
68+
p = p->nextSibling;
69+
}
70+
printf("%s\n",p->name);printf("%s\n",p->nextSibling->name);
71+
fflush(stdout);
72+
p->nextSibling = nownode->nextSibling;
73+
nownode->nextSibling = nullptr;
74+
nownode->printDeletedNodesToFile(outputFile);
75+
delete nownode;
76+
}
77+
std::cout<<"Success!"<<std::endl;
78+
}
79+
80+
}
81+
outputFile.close();
82+
}

directorysimulator.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef DIRECTORY_SIMULATOR_H
2+
#define DIRECTORY_SIMULATOR_H
3+
4+
#include <iostream>
5+
#include <fstream>
6+
#include <sstream>
7+
#include <vector>
8+
#include "treenode.h"
9+
10+
class DirectoryOperation {
11+
public:
12+
std::string fullPath;
13+
std::string parentDirectory;
14+
char operation;
15+
std::string time;
16+
std::string size;
17+
};
18+
19+
class DirectorySimulator {
20+
private:
21+
std::vector<DirectoryOperation> directoryOperations;
22+
TreeNode *node;
23+
24+
public:
25+
DirectorySimulator(const std::string& filename,TreeNode *currentnode);
26+
void executeDirectoryOperations(const char *);
27+
};
28+
29+
#endif // DIRECTORY_SIMULATOR_H

0 commit comments

Comments
 (0)