mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
FileManager: Move mass-copy code from DirectoryView to FileUtils
This is preparation for calling it from FileManager/main.cpp Also made file_operation_windows take NonnullRefPtrs.
This commit is contained in:
parent
9060310840
commit
d8fb8b9583
4 changed files with 78 additions and 78 deletions
|
@ -1,10 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "FileUtils.h"
|
||||
#include "FileOperationProgressWidget.h"
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
|
@ -12,7 +14,9 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace FileUtils {
|
||||
namespace FileManager {
|
||||
|
||||
HashTable<NonnullRefPtr<GUI::Window>> file_operation_windows;
|
||||
|
||||
void delete_path(String const& path, GUI::Window* parent_window)
|
||||
{
|
||||
|
@ -67,4 +71,64 @@ void delete_paths(Vector<String> const& paths, bool should_confirm, GUI::Window*
|
|||
}
|
||||
}
|
||||
|
||||
void run_file_operation([[maybe_unused]] FileOperation operation, Vector<String> const& sources, String const& destination, GUI::Window* parent_window)
|
||||
{
|
||||
int pipe_fds[2];
|
||||
if (pipe(pipe_fds) < 0) {
|
||||
perror("pipe");
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
pid_t child_pid = fork();
|
||||
if (child_pid < 0) {
|
||||
perror("fork");
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (!child_pid) {
|
||||
if (close(pipe_fds[0]) < 0) {
|
||||
perror("close");
|
||||
_exit(1);
|
||||
}
|
||||
if (dup2(pipe_fds[1], STDOUT_FILENO) < 0) {
|
||||
perror("dup2");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
Vector<char const*> file_operation_args;
|
||||
file_operation_args.append("/bin/FileOperation");
|
||||
file_operation_args.append("Copy");
|
||||
|
||||
for (auto& source : sources)
|
||||
file_operation_args.append(source.characters());
|
||||
|
||||
file_operation_args.append(destination.characters());
|
||||
file_operation_args.append(nullptr);
|
||||
|
||||
if (execvp(file_operation_args.first(), const_cast<char**>(file_operation_args.data())) < 0) {
|
||||
perror("execvp");
|
||||
_exit(1);
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
} else {
|
||||
if (close(pipe_fds[1]) < 0) {
|
||||
perror("close");
|
||||
_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
auto window = GUI::Window::construct();
|
||||
file_operation_windows.set(window);
|
||||
|
||||
auto pipe_input_file = Core::File::construct();
|
||||
pipe_input_file->open(pipe_fds[0], Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
|
||||
|
||||
window->set_title("Copying Files...");
|
||||
window->set_main_widget<FileOperationProgressWidget>(pipe_input_file);
|
||||
window->resize(320, 190);
|
||||
if (parent_window)
|
||||
window->center_within(*parent_window);
|
||||
window->show();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue