|
|
@@ -11,6 +11,8 @@
|
|
|
|
|
|
using namespace craftlab::fakeraid::ui;
|
|
|
|
|
|
+std::string mergePath(const std::string& a, const std::string& b);
|
|
|
+
|
|
|
MainWindow::MainWindow(const std::vector<std::string>& dirList)
|
|
|
: fileListItemModel(std::make_unique<QStandardItemModel>(this)),
|
|
|
ui(std::make_unique<Ui_MainWindow>()),
|
|
|
@@ -25,7 +27,8 @@ MainWindow::MainWindow(const std::vector<std::string>& dirList)
|
|
|
ui->breadcrumb->setFixedHeight(36);
|
|
|
|
|
|
connect(ui->actionOuvrir, &QAction::triggered, this, &MainWindow::MenuBarActionTrigerred);
|
|
|
- connect(ui->actionRefresh, &QAction::triggered, this, &MainWindow::OnEngineUpdated);
|
|
|
+ connect(ui->actionRefresh, &QAction::triggered, this, &MainWindow::OnPathChanged);
|
|
|
+ connect(ui->actionScan_for_errors, &QAction::triggered, this, &MainWindow::RequestDeepScan);
|
|
|
connect(ui->listView, &QListView::doubleClicked, this, &MainWindow::FileListItemEntered);
|
|
|
connect(ui->breadcrumb, &craftlab::ui::Breadcrumb::SelectionChanged, this, &MainWindow::OnBreadcrumbSelection);
|
|
|
ui->listView->addAction("Open", [this]() { FileListItemEntered(ui->listView->currentIndex()); });
|
|
|
@@ -43,6 +46,19 @@ MainWindow::~MainWindow()
|
|
|
fileWatcher->deleteLater();
|
|
|
}
|
|
|
|
|
|
+void MainWindow::RequestDeepScan()
|
|
|
+{
|
|
|
+ assert(nullptr != engine);
|
|
|
+
|
|
|
+ DiffResult allResults= FileDiff().Process(*engine, engine->ListFilesRecur());
|
|
|
+ if (allResults.HasError())
|
|
|
+ currentDiffResult = std::make_unique<DiffResult>(ConflictModal::Display(*engine, allResults, true));
|
|
|
+ else
|
|
|
+ QMessageBox::information(window.get(), window->windowTitle(), "Folders are identical");
|
|
|
+
|
|
|
+ ListFiles(true);
|
|
|
+}
|
|
|
+
|
|
|
void MainWindow::FileListItemEntered(const QModelIndex& index)
|
|
|
{
|
|
|
if (index.isValid() && currentDiffResult)
|
|
|
@@ -96,11 +112,10 @@ void MainWindow::OnBreadcrumbSelection(int index)
|
|
|
std::vector<std::string> path;
|
|
|
const std::deque<std::string> currenPath = engine->GetCurrentDir();
|
|
|
|
|
|
- window->setEnabled(false);
|
|
|
for (int i = 1; i <= index; ++i)
|
|
|
path.push_back(currenPath[i -1]);
|
|
|
if (engine->SetWorkingDirectory(path))
|
|
|
- OnEngineUpdated();
|
|
|
+ OnPathChanged();
|
|
|
}
|
|
|
|
|
|
void MainWindow::UpdateBreadcrumb()
|
|
|
@@ -115,6 +130,7 @@ void MainWindow::UpdateBreadcrumb()
|
|
|
void MainWindow::UpdateFileList()
|
|
|
{
|
|
|
fileListItemModel->clear();
|
|
|
+ std::sort(currentDiffResult->correctFiles.begin(), currentDiffResult->correctFiles.end(), [](const File& a, const File& b) { return a.fileName < b.fileName; });
|
|
|
for (const File& file : currentDiffResult->correctFiles)
|
|
|
fileListItemModel->appendRow(new FileItem(*ui->listView, engine->GetRootPaths(), file));
|
|
|
std::vector<std::string> allFilenames;
|
|
|
@@ -126,20 +142,15 @@ void MainWindow::UpdateFileList()
|
|
|
fileListItemModel->appendRow(new FileItem(*ui->listView, engine->GetRootPaths(), currentDiffResult->FileList[file], false));
|
|
|
}
|
|
|
|
|
|
-void MainWindow::ListFiles(bool ignoreAll)
|
|
|
+void MainWindow::ListFiles(bool ignoreErrors)
|
|
|
{
|
|
|
- if (!engine)
|
|
|
- return;
|
|
|
- currentDiffResult = std::make_unique<DiffResult>(FileDiff().Process(engine->ListFiles()));
|
|
|
- if (!ignoreAll && (!currentDiffResult->differentFiles.empty() || !currentDiffResult->missingDirs.empty() || !currentDiffResult->missingFiles.empty()))
|
|
|
- currentDiffResult = std::make_unique<DiffResult>(ConflictModal::Display(*engine, *currentDiffResult));
|
|
|
- std::sort(currentDiffResult->correctFiles.begin(), currentDiffResult->correctFiles.end(), [](const File& a, const File& b) { return a.fileName < b.fileName; });
|
|
|
-
|
|
|
+ assert(nullptr != engine);
|
|
|
+ currentDiffResult = std::make_unique<DiffResult>(FileDiff().Process(*engine, engine->ListFiles()));
|
|
|
+ if (!ignoreErrors && currentDiffResult->HasError())
|
|
|
+ currentDiffResult = std::make_unique<DiffResult>(ConflictModal::Display(*engine, *currentDiffResult, false));
|
|
|
UpdateFileList();
|
|
|
}
|
|
|
|
|
|
-std::string mergePath(const std::string& a, const std::string& b);
|
|
|
-
|
|
|
void MainWindow::FileEdit(const File& file)
|
|
|
{
|
|
|
assert(nullptr != engine);
|
|
|
@@ -168,7 +179,7 @@ void MainWindow::OnListViewDoubleClick(const FileAndSum& file)
|
|
|
if (engine)
|
|
|
{
|
|
|
engine->Cd(file.fileName);
|
|
|
- OnEngineUpdated();
|
|
|
+ OnPathChanged();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
@@ -180,26 +191,26 @@ void MainWindow::OnListViewDoubleClick(const FileAndSum& file)
|
|
|
if (!engine)
|
|
|
return;
|
|
|
DiffResult askConflict;
|
|
|
- bool missingFile = currentDiffResult->missingFiles.find(file.fileName) != currentDiffResult->missingFiles.end();
|
|
|
- bool missingDir = currentDiffResult->missingDirs.find(file.fileName) != currentDiffResult->missingDirs.end();
|
|
|
- askConflict.FileList[file.fileName] = file;
|
|
|
+ bool missingFile = currentDiffResult->missingFiles.find(engine->BuildCurrentDirPath(file)) != currentDiffResult->missingFiles.end();
|
|
|
+ bool missingDir = currentDiffResult->missingDirs.find(engine->BuildCurrentDirPath(file)) != currentDiffResult->missingDirs.end();
|
|
|
+ askConflict.FileList[engine->BuildCurrentDirPath(file)] = file;
|
|
|
if (missingFile)
|
|
|
- askConflict.missingFiles[file.fileName] = currentDiffResult->missingFiles[file.fileName];
|
|
|
+ askConflict.missingFiles[engine->BuildCurrentDirPath(file)] = currentDiffResult->missingFiles[engine->BuildCurrentDirPath(file)];
|
|
|
else if (missingDir)
|
|
|
- askConflict.missingDirs[file.fileName] = currentDiffResult->missingDirs[file.fileName];
|
|
|
+ askConflict.missingDirs[engine->BuildCurrentDirPath(file)] = currentDiffResult->missingDirs[engine->BuildCurrentDirPath(file)];
|
|
|
else
|
|
|
- askConflict.differentFiles[file.fileName] = currentDiffResult->differentFiles[file.fileName];
|
|
|
- const DiffResult& result = ConflictModal::Display(*engine, askConflict);
|
|
|
+ askConflict.differentFiles[engine->BuildCurrentDirPath(file)] = currentDiffResult->differentFiles[engine->BuildCurrentDirPath(file)];
|
|
|
+ const DiffResult& result = ConflictModal::Display(*engine, askConflict, false);
|
|
|
if (result.missingDirs.empty() && result.missingFiles.empty() && result.differentFiles.empty())
|
|
|
{
|
|
|
if (!result.correctFiles.empty())
|
|
|
currentDiffResult->correctFiles.push_back(file);
|
|
|
if (missingFile)
|
|
|
- currentDiffResult->missingFiles.erase(currentDiffResult->missingFiles.find(file.fileName));
|
|
|
+ currentDiffResult->missingFiles.erase(currentDiffResult->missingFiles.find(engine->BuildCurrentDirPath(file)));
|
|
|
else if (missingDir)
|
|
|
- currentDiffResult->missingDirs.erase(currentDiffResult->missingDirs.find(file.fileName));
|
|
|
+ currentDiffResult->missingDirs.erase(currentDiffResult->missingDirs.find(engine->BuildCurrentDirPath(file)));
|
|
|
else
|
|
|
- currentDiffResult->differentFiles.erase(currentDiffResult->differentFiles.find(file.fileName));
|
|
|
+ currentDiffResult->differentFiles.erase(currentDiffResult->differentFiles.find(engine->BuildCurrentDirPath(file)));
|
|
|
UpdateFileList();
|
|
|
}
|
|
|
}
|
|
|
@@ -209,7 +220,7 @@ void MainWindow::OnFileWatcherTrigger(const QString& path)
|
|
|
ListFiles(true);
|
|
|
}
|
|
|
|
|
|
-void MainWindow::OnEngineUpdated()
|
|
|
+void MainWindow::OnPathChanged()
|
|
|
{
|
|
|
window->setEnabled(false);
|
|
|
fileWatcher->deleteLater();
|
|
|
@@ -231,7 +242,7 @@ bool MainWindow::TryOpenningDir(const std::vector<std::string>& folders)
|
|
|
return false;
|
|
|
}
|
|
|
engine.reset(newEngine);
|
|
|
- OnEngineUpdated();
|
|
|
+ OnPathChanged();
|
|
|
return true;
|
|
|
}
|
|
|
|