mirror of
https://github.com/Drimiteros/Da-Deep-Search.git
synced 2026-04-28 02:01:17 -05:00
Add files via upload
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
#include "App.h"
|
||||
|
||||
App::App() {
|
||||
|
||||
|
||||
window.create(VideoMode(1000, 850), version, Style::Close);
|
||||
|
||||
HWND hwnd = window.getSystemHandle();
|
||||
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW);
|
||||
|
||||
cursor.setSize(Vector2f(2, 2));
|
||||
view_bounds.setFillColor(Color(45, 45, 50));
|
||||
view_bounds.setPosition(0, 200);
|
||||
view_bounds.setPosition(0, 205);
|
||||
view_bounds.setSize(Vector2f(window.getSize().x, 800));
|
||||
|
||||
fetch_file.get_available_drives();
|
||||
drive_explorer.get_available_drives();
|
||||
}
|
||||
|
||||
void App::events() {
|
||||
@@ -17,8 +20,8 @@ void App::events() {
|
||||
if (event.type == Event::Closed)
|
||||
window.close();
|
||||
|
||||
input_events.type_event(event, search_bar_string, start_search, drive_offset);
|
||||
input_events.click_event(event, is_click_pressed);
|
||||
input_events.keyboard_event(event, search_bar_string, start_search);
|
||||
input_events.mouse_event(event, is_click_pressed, scroll_value, window);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +30,10 @@ void App::loop() {
|
||||
while (window.isOpen()) {
|
||||
events();
|
||||
|
||||
update();
|
||||
|
||||
window.clear(Color(55, 55, 60));
|
||||
|
||||
update();
|
||||
|
||||
draw();
|
||||
|
||||
window.display();
|
||||
@@ -39,14 +42,25 @@ void App::loop() {
|
||||
|
||||
void App::update() {
|
||||
|
||||
// Update the window state
|
||||
HWND hwnd = window.getSystemHandle();
|
||||
if (Keyboard::isKeyPressed(Keyboard::Space) && Keyboard::isKeyPressed(Keyboard::LControl) && window_state_clock.getElapsedTime().asSeconds() > 0.4) {
|
||||
if (IsIconic(hwnd))
|
||||
ShowWindow(hwnd, SW_RESTORE);
|
||||
else
|
||||
ShowWindow(hwnd, SW_MINIMIZE);
|
||||
window_state_clock.restart();
|
||||
}
|
||||
|
||||
cursor.setPosition(window.mapPixelToCoords(Mouse::getPosition(window)));
|
||||
searchbar.update(window, search_bar_string);
|
||||
fetch_file.found_file(search_bar_string, start_search, drive_offset);
|
||||
fetch_file.execute_file(cursor, is_click_pressed);
|
||||
drive_explorer.select_drives(cursor, is_click_pressed);
|
||||
drive_explorer.found_file(window, search_bar_string, start_search);
|
||||
drive_explorer.execute_file(cursor, is_click_pressed);
|
||||
}
|
||||
|
||||
void App::draw() {
|
||||
window.draw(view_bounds);
|
||||
searchbar.draw(window);
|
||||
fetch_file.draw(window);
|
||||
drive_explorer.draw(window, cursor, start_search, scroll_value, view_bounds);
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#define NOMINMAX
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "Input_events.h"
|
||||
#include "Searchbar.h"
|
||||
#include "Fetch_file.h"
|
||||
#include "Drive_explorer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace sf;
|
||||
@@ -17,15 +20,18 @@ private:
|
||||
wstring search_bar_string;
|
||||
bool start_search = false;
|
||||
bool is_click_pressed = false;
|
||||
int drive_offset = 0;
|
||||
int scroll_value = 0;
|
||||
|
||||
RectangleShape cursor;
|
||||
RectangleShape view_bounds;
|
||||
|
||||
HWND hwnd;
|
||||
Clock window_state_clock;
|
||||
|
||||
public:
|
||||
Input_events input_events;
|
||||
Searchbar searchbar;
|
||||
Fetch_file fetch_file;
|
||||
Drive_explorer drive_explorer;
|
||||
|
||||
App();
|
||||
void events();
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
#include "Drive_explorer.h"
|
||||
|
||||
Drive_explorer::Drive_explorer() {
|
||||
|
||||
font.loadFromFile("src/Fonts/LTSuperior-Medium.otf");
|
||||
found_files_text.setFont(font);
|
||||
found_files_text.setFillColor(Color(255, 210, 190));
|
||||
found_files_text.setCharacterSize(15);
|
||||
|
||||
drive_info_text.setFont(font);
|
||||
drive_info_text.setCharacterSize(15);
|
||||
drive_info_text.setFillColor(Color(225, 180, 160));
|
||||
drive_info_text.setString("Drives to search: ");
|
||||
drive_info_text.setPosition(5, 180);
|
||||
|
||||
search_state_text.setFont(font);
|
||||
search_state_text.setCharacterSize(15);
|
||||
search_state_text.setFillColor(Color(225, 180, 160));
|
||||
search_state_text.setString("Searching...");
|
||||
search_state_text.setOrigin(search_state_text.getLocalBounds().width / 2, search_state_text.getLocalBounds().height / 2);
|
||||
|
||||
file_select_bar.setSize(Vector2f(1000, 20));
|
||||
file_select_bar.setFillColor(Color(255, 210, 190));
|
||||
file_select_bar.setPosition(9999, 9999);
|
||||
}
|
||||
|
||||
void Drive_explorer::get_available_drives() {
|
||||
|
||||
DWORD driveMask = GetLogicalDrives();
|
||||
for (char drive = 'A'; drive <= 'Z'; drive++) {
|
||||
// If drive exists
|
||||
if (driveMask & (1 << (drive - 'A'))) {
|
||||
drive_letter_text.push_back(Text());
|
||||
drive_letter_text.back().setFont(font);
|
||||
drive_letter_text.back().setCharacterSize(15);
|
||||
drive_letter_text.back().setFillColor(Color(105, 60, 40));
|
||||
drive_letter_text.back().setPosition(10, 180);
|
||||
drive_letter_text.back().setString(wstring(1, drive));
|
||||
|
||||
drive_select_box.push_back(RectangleShape());
|
||||
drive_select_box.back().setSize(Vector2f(15, 15));
|
||||
drive_select_box.back().setFillColor(Color(255, 255, 150));
|
||||
|
||||
disabled_drive.push_back(0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < drive_letter_text.size(); i++) {
|
||||
drive_select_box[i].setPosition(90 + (i * 20), 183);
|
||||
drive_letter_text[i].setPosition(90 + (i * 20), 180);
|
||||
}
|
||||
drive_info_text.setString("Scan drives: ");
|
||||
}
|
||||
|
||||
void Drive_explorer::select_drives(RectangleShape& cursor, bool& is_click_pressed) {
|
||||
|
||||
if (is_click_pressed) {
|
||||
for (int i = 0; i < drive_letter_text.size(); i++) {
|
||||
if (cursor.getGlobalBounds().intersects(drive_select_box[i].getGlobalBounds()) && disabled_drive[i] == false) {
|
||||
disabled_drive[i] = true;
|
||||
is_click_pressed = false;
|
||||
break;
|
||||
}
|
||||
if (cursor.getGlobalBounds().intersects(drive_select_box[i].getGlobalBounds()) && disabled_drive[i] == true) {
|
||||
disabled_drive[i] = false;
|
||||
is_click_pressed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Drive_explorer::found_file(RenderWindow& window, wstring& search_bar_string, bool& start_search) {
|
||||
|
||||
if (begin_iteration) {
|
||||
found_files_text_vector.clear();
|
||||
found_files_string_vector.clear();
|
||||
try {
|
||||
if ((drive_letter_text.size() - 1) + drive_offset < drive_letter_text.size()) {
|
||||
for (int i = (drive_letter_text.size() - 1) + drive_offset; i >= 0; i--) {
|
||||
if (disabled_drive[i] == false) {
|
||||
wstring current_drive = drive_letter_text[i].getString();
|
||||
root_path = current_drive + ":\\";
|
||||
wcout << "Searching path:" << root_path << endl;
|
||||
for (const auto& entry : fs::recursive_directory_iterator(root_path, fs::directory_options::skip_permission_denied)) {
|
||||
iterations++;
|
||||
wstring ex = entry.path().filename().wstring();
|
||||
if (ex.find(search_bar_string) != wstring::npos) {
|
||||
found_files_text.setString(entry.path().wstring());
|
||||
found_files_text_vector.push_back(found_files_text);
|
||||
found_files_string_vector.push_back(entry.path().wstring());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
wcout << "No more results found." << endl;
|
||||
wcout << "Directory iterations: " << iterations << endl;
|
||||
wcout << "Files found: " << found_files_text_vector.size() << "\n" << endl;
|
||||
start_search = false;
|
||||
begin_iteration = false;
|
||||
drive_offset = 0;
|
||||
}
|
||||
}
|
||||
catch (const fs::filesystem_error& e) {
|
||||
wcerr << "Error: " << e.what() << endl;
|
||||
wcout << "No more results found." << endl;
|
||||
wcout << "Directory iterations: " << iterations << endl;
|
||||
wcout << "Files found: " << found_files_text_vector.size() << "\n" << endl;
|
||||
drive_offset++;
|
||||
start_search = false;
|
||||
begin_iteration = false;
|
||||
drive_offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Drive_explorer::execute_file(RectangleShape& cursor, bool& is_click_pressed) {
|
||||
|
||||
if (is_click_pressed) {
|
||||
for (int i = 0; i < found_files_text_vector.size(); i++) {
|
||||
if (cursor.getGlobalBounds().intersects(found_files_text_vector[i].getGlobalBounds())) {
|
||||
|
||||
// Convert wstring to const wchar_t* for CreateProcessW
|
||||
const wchar_t* program = found_files_string_vector[i].c_str();
|
||||
|
||||
// Execute and wait for process to finish
|
||||
if (ShellExecuteW(NULL, L"open", program, NULL, NULL, SW_SHOWNORMAL) <= (HINSTANCE)32)
|
||||
wcerr << L"Failed to open file. Error: " << GetLastError() << endl;
|
||||
else
|
||||
wcerr << L"Failed to start process. Error: " << GetLastError() << endl;
|
||||
|
||||
is_click_pressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Drive_explorer::draw(RenderWindow& window, RectangleShape& cursor, bool& start_search, int& scroll_value, RectangleShape& view_bounds) {
|
||||
|
||||
for (int i = 0; i < drive_letter_text.size(); i++) {
|
||||
if (!disabled_drive[i])
|
||||
window.draw(drive_select_box[i]);
|
||||
window.draw(drive_letter_text[i]);
|
||||
}
|
||||
|
||||
window.draw(drive_info_text);
|
||||
if (start_search) {
|
||||
search_state_text.setPosition(window.getSize().x / 2, window.getSize().y / 2 - 250);
|
||||
window.draw(search_state_text);
|
||||
begin_iteration = true;
|
||||
}
|
||||
|
||||
for (int i = 0;i < found_files_text_vector.size();i++) {
|
||||
if (cursor.getGlobalBounds().intersects(found_files_text_vector[i].getGlobalBounds())) {
|
||||
file_select_bar.setPosition(found_files_text_vector[i].getPosition());
|
||||
found_files_text_vector[i].setFillColor(Color::Black);
|
||||
}
|
||||
if (!cursor.getGlobalBounds().intersects(found_files_text_vector[i].getGlobalBounds())) {
|
||||
found_files_text_vector[i].setFillColor(Color(255, 210, 190));
|
||||
file_select_bar.setPosition(9999, 9999);
|
||||
}
|
||||
window.draw(file_select_bar);
|
||||
found_files_text_vector[i].setPosition(10, 210 + (i * 25) + (scroll_value * 25));
|
||||
if (found_files_text_vector[i].getGlobalBounds().intersects(view_bounds.getGlobalBounds()))
|
||||
window.draw(found_files_text_vector[i]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
#define NOMINMAX
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace sf;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
class Drive_explorer
|
||||
{
|
||||
private:
|
||||
Font font;
|
||||
Text found_files_text;
|
||||
Text drive_info_text;
|
||||
Text search_state_text;
|
||||
RectangleShape file_select_bar;
|
||||
vector<Text> found_files_text_vector;
|
||||
vector<Text> drive_letter_text;
|
||||
vector<RectangleShape> drive_select_box;
|
||||
vector<bool> disabled_drive;
|
||||
|
||||
public:
|
||||
vector<wstring> found_files_string_vector;
|
||||
wstring root_path;
|
||||
int iterations = 0;
|
||||
int counter = 0;
|
||||
int get_position = 0;
|
||||
int drive_offset = 0;
|
||||
bool begin_iteration = false;
|
||||
|
||||
Drive_explorer();
|
||||
void get_available_drives();
|
||||
void select_drives(RectangleShape& cursor, bool& is_click_pressed);
|
||||
void found_file(RenderWindow& window, wstring& search_bar_string, bool& start_search);
|
||||
void execute_file(RectangleShape& cursor, bool& is_click_pressed);
|
||||
void draw(RenderWindow& window, RectangleShape& cursor, bool& start_search, int& scroll_value, RectangleShape& view_bounds);
|
||||
};
|
||||
|
||||
+21
-11
@@ -4,24 +4,34 @@ Input_events::Input_events() {
|
||||
|
||||
}
|
||||
|
||||
void Input_events::type_event(Event& event, wstring& search_bar_string, bool& start_search, int& drive_offset) {
|
||||
if (event.type == Event::TextEntered && !Keyboard::isKeyPressed(Keyboard::Enter) && !Keyboard::isKeyPressed(Keyboard::Backspace))
|
||||
void Input_events::keyboard_event(Event& event, wstring& search_bar_string, bool& start_search) {
|
||||
if ((event.type == Event::TextEntered && !Keyboard::isKeyPressed(Keyboard::Enter) && !Keyboard::isKeyPressed(Keyboard::Backspace)) && !Keyboard::isKeyPressed(Keyboard::LControl))
|
||||
search_bar_string += event.text.unicode;
|
||||
if (event.type == Event::TextEntered && !Keyboard::isKeyPressed(Keyboard::Enter) && Keyboard::isKeyPressed(Keyboard::Backspace))
|
||||
search_bar_string = search_bar_string.substr(0, search_bar_string.size() - 1);
|
||||
if (event.type == Event::TextEntered && !Keyboard::isKeyPressed(Keyboard::Enter) && Keyboard::isKeyPressed(Keyboard::Backspace) && Keyboard::isKeyPressed(Keyboard::LShift))
|
||||
search_bar_string.clear();
|
||||
if (Keyboard::isKeyPressed(Keyboard::Enter)) {
|
||||
if (Keyboard::isKeyPressed(Keyboard::Enter))
|
||||
start_search = true;
|
||||
drive_offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Input_events::click_event(Event& event, bool& is_click_pressed) {
|
||||
if (event.type == Event::MouseButtonPressed) {
|
||||
if (Mouse::isButtonPressed(Mouse::Left))
|
||||
is_click_pressed = true;
|
||||
void Input_events::mouse_event(Event& event, bool& is_click_pressed, int& scroll_value, RenderWindow& window) {
|
||||
|
||||
if (window.hasFocus()) {
|
||||
if (event.type == Event::MouseButtonPressed) {
|
||||
if (Mouse::isButtonPressed(Mouse::Left))
|
||||
is_click_pressed = true;
|
||||
}
|
||||
else
|
||||
is_click_pressed = false;
|
||||
|
||||
if (event.type == Event::MouseWheelScrolled) {
|
||||
if (event.mouseWheelScroll.wheel == Mouse::VerticalWheel) {
|
||||
if (event.mouseWheelScroll.delta > 0)
|
||||
scroll_value++;
|
||||
if (event.mouseWheelScroll.delta < 0)
|
||||
scroll_value--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
is_click_pressed = false;
|
||||
}
|
||||
+5
-2
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#define NOMINMAX
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
using namespace std;
|
||||
@@ -11,7 +14,7 @@ private:
|
||||
|
||||
public:
|
||||
Input_events();
|
||||
void type_event(Event& event, wstring& search_bar_string, bool& start_search, int& drive_offset);
|
||||
void click_event(Event& event, bool& is_click_pressed);
|
||||
void keyboard_event(Event& event, wstring& search_bar_string, bool& start_search);
|
||||
void mouse_event(Event& event, bool& is_click_pressed, int& scroll_value, RenderWindow& window);
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ Searchbar::Searchbar() {
|
||||
|
||||
void Searchbar::update(RenderWindow& window, wstring& search_bar_string) {
|
||||
search_bar_text.setOrigin(search_bar_text.getLocalBounds().width / 2, 0);
|
||||
search_bar_text.setPosition(window.getSize().x / 2, window.getSize().y / 2 - 400);
|
||||
search_bar_text.setPosition(window.getSize().x / 2, window.getSize().y / 2 - 350);
|
||||
|
||||
if (search_bar_string.size() == 0)
|
||||
search_bar_text.setString("Start typing...");
|
||||
|
||||
Reference in New Issue
Block a user