mirror of
https://github.com/Drimiteros/Da-Deep-Search.git
synced 2026-02-05 13:38:30 -06:00
Add files via upload
This commit is contained in:
52
App.cpp
Normal file
52
App.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "App.h"
|
||||
|
||||
App::App() {
|
||||
|
||||
window.create(VideoMode(1000, 850), version, Style::Close);
|
||||
|
||||
cursor.setSize(Vector2f(2, 2));
|
||||
view_bounds.setFillColor(Color(45, 45, 50));
|
||||
view_bounds.setPosition(0, 200);
|
||||
view_bounds.setSize(Vector2f(window.getSize().x, 800));
|
||||
|
||||
fetch_file.get_available_drives();
|
||||
}
|
||||
|
||||
void App::events() {
|
||||
while (window.pollEvent(event)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void App::loop() {
|
||||
|
||||
while (window.isOpen()) {
|
||||
events();
|
||||
|
||||
update();
|
||||
|
||||
window.clear(Color(55, 55, 60));
|
||||
|
||||
draw();
|
||||
|
||||
window.display();
|
||||
}
|
||||
}
|
||||
|
||||
void App::update() {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void App::draw() {
|
||||
window.draw(view_bounds);
|
||||
searchbar.draw(window);
|
||||
fetch_file.draw(window);
|
||||
}
|
||||
36
App.h
Normal file
36
App.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "Input_events.h"
|
||||
#include "Searchbar.h"
|
||||
#include "Fetch_file.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace sf;
|
||||
|
||||
class App
|
||||
{
|
||||
private:
|
||||
string version = "Da Deep Search v.2.0";
|
||||
RenderWindow window;
|
||||
Event event;
|
||||
wstring search_bar_string;
|
||||
bool start_search = false;
|
||||
bool is_click_pressed = false;
|
||||
int drive_offset = 0;
|
||||
|
||||
RectangleShape cursor;
|
||||
RectangleShape view_bounds;
|
||||
|
||||
public:
|
||||
Input_events input_events;
|
||||
Searchbar searchbar;
|
||||
Fetch_file fetch_file;
|
||||
|
||||
App();
|
||||
void events();
|
||||
void loop();
|
||||
void update();
|
||||
void draw();
|
||||
};
|
||||
|
||||
@@ -1,66 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <Windows.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include "App.h"
|
||||
|
||||
using namespace std;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int main() {
|
||||
_setmode(_fileno(stdout), _O_WTEXT);
|
||||
_setmode(_fileno(stdin), _O_WTEXT);
|
||||
|
||||
wstring root_path = L"D:\\";
|
||||
wstring target_file;
|
||||
vector<wstring>files_found;
|
||||
int iterations = 0;
|
||||
int files_found_count = 0;
|
||||
int counter = 0;
|
||||
int get_position = 0;
|
||||
|
||||
wcout << L"Enter target file or directory: ";
|
||||
getline(wcin, target_file);
|
||||
system("cls");
|
||||
wcout << L"Searching for " << target_file << "..." << endl;
|
||||
|
||||
try {
|
||||
for (const auto& entry : fs::recursive_directory_iterator(root_path, fs::directory_options::skip_permission_denied)) {
|
||||
iterations++;
|
||||
wstring ex = entry.path().filename().wstring();
|
||||
//temp
|
||||
for (int i = 0; i < target_file.size(); i++) {
|
||||
for (int a = 0; a < ex.size(); a++) {
|
||||
if (target_file[i] == ex[a + get_position] && a + get_position <= ex.size()) {
|
||||
get_position = a + 1;
|
||||
counter++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (counter == target_file.size()) {
|
||||
files_found.push_back(entry.path().wstring());
|
||||
files_found_count++;
|
||||
counter = 0;
|
||||
get_position = 0;
|
||||
}
|
||||
if (entry.path().filename().wstring() == target_file) {
|
||||
files_found.push_back(entry.path().wstring());
|
||||
files_found_count++;
|
||||
}
|
||||
}
|
||||
system("cls");
|
||||
wcout << "No more results found." << endl;
|
||||
}
|
||||
catch (const fs::filesystem_error& e) {
|
||||
wcerr << "Error: " << e.what() << endl;
|
||||
}
|
||||
|
||||
system("cls");
|
||||
wcout << "Directory iterations: " << iterations << endl;
|
||||
wcout << "Files found: "<< files_found_count << "\n" << endl;
|
||||
for (int i = 0;i < files_found.size();i++)
|
||||
wcout << "[*] " << files_found[i] << endl;
|
||||
|
||||
return 0;
|
||||
App app;
|
||||
app.loop();
|
||||
}
|
||||
|
||||
78
Fetch_file.cpp
Normal file
78
Fetch_file.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "Fetch_file.h"
|
||||
|
||||
Fetch_file::Fetch_file() {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void Fetch_file::get_available_drives() {
|
||||
DWORD driveMask = GetLogicalDrives();
|
||||
for (char drive = 'A'; drive <= 'Z'; drive++) {
|
||||
// If drive exists
|
||||
if (driveMask & (1 << (drive - 'A')))
|
||||
drive_letter.push_back(drive);
|
||||
}
|
||||
}
|
||||
|
||||
void Fetch_file::found_file(wstring& search_bar_string, bool& start_search, int& drive_offset) {
|
||||
if (start_search) {
|
||||
try {
|
||||
if ((drive_letter.size() - 1) + drive_offset < drive_letter.size()) {
|
||||
for (int i = (drive_letter.size() - 1) + drive_offset; i >= 0; i--) {
|
||||
wstring convert_drive_wchar_t(1, drive_letter[i]);
|
||||
root_path = convert_drive_wchar_t + ":\\";
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
start_search = false;
|
||||
wcout << "No more results found." << endl;
|
||||
wcout << "Directory iterations: " << iterations << endl;
|
||||
wcout << "Files found: " << found_files_text_vector.size() << "\n" << endl;
|
||||
}
|
||||
}
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Fetch_file::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 Fetch_file::draw(RenderWindow& window) {
|
||||
|
||||
for (int i = 0;i < found_files_text_vector.size();i++) {
|
||||
found_files_text_vector[i].setPosition(10, 210 + (i * 25));
|
||||
window.draw(found_files_text_vector[i]);
|
||||
}
|
||||
}
|
||||
36
Fetch_file.h
Normal file
36
Fetch_file.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#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 Fetch_file
|
||||
{
|
||||
private:
|
||||
Font font;
|
||||
Text found_files_text;
|
||||
vector<Text> found_files_text_vector;
|
||||
vector<wchar_t> drive_letter;
|
||||
|
||||
public:
|
||||
vector<wstring> found_files_string_vector;
|
||||
wstring root_path;
|
||||
int iterations = 0;
|
||||
int counter = 0;
|
||||
int get_position = 0;
|
||||
|
||||
Fetch_file();
|
||||
void get_available_drives();
|
||||
void found_file(wstring& search_bar_string, bool& start_search, int& drive_offset);
|
||||
void execute_file(RectangleShape& cursor, bool& is_click_pressed);
|
||||
void draw(RenderWindow& window);
|
||||
};
|
||||
|
||||
27
Input_events.cpp
Normal file
27
Input_events.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "Input_events.h"
|
||||
|
||||
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))
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
else
|
||||
is_click_pressed = false;
|
||||
}
|
||||
17
Input_events.h
Normal file
17
Input_events.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace sf;
|
||||
|
||||
class Input_events
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
||||
24
Searchbar.cpp
Normal file
24
Searchbar.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "Searchbar.h"
|
||||
|
||||
Searchbar::Searchbar() {
|
||||
|
||||
font.loadFromFile("src/Fonts/LTSuperior-Medium.otf");
|
||||
search_bar_text.setFont(font);
|
||||
search_bar_text.setFillColor(Color(255, 180, 150));
|
||||
search_bar_text.setString("Start typing...");
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (search_bar_string.size() == 0)
|
||||
search_bar_text.setString("Start typing...");
|
||||
else
|
||||
search_bar_text.setString(search_bar_string);
|
||||
}
|
||||
|
||||
void Searchbar::draw(RenderWindow& window) {
|
||||
|
||||
window.draw(search_bar_text);
|
||||
}
|
||||
20
Searchbar.h
Normal file
20
Searchbar.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace sf;
|
||||
|
||||
class Searchbar
|
||||
{
|
||||
private:
|
||||
Font font;
|
||||
Text search_bar_text;
|
||||
RectangleShape background;
|
||||
|
||||
public:
|
||||
Searchbar();
|
||||
void update(RenderWindow& window, wstring& search_bar_string);
|
||||
void draw(RenderWindow& window);
|
||||
};
|
||||
|
||||
BIN
src/Fonts/LTSuperior-Black.otf
Normal file
BIN
src/Fonts/LTSuperior-Black.otf
Normal file
Binary file not shown.
BIN
src/Fonts/LTSuperior-Bold.otf
Normal file
BIN
src/Fonts/LTSuperior-Bold.otf
Normal file
Binary file not shown.
BIN
src/Fonts/LTSuperior-ExtraBold.otf
Normal file
BIN
src/Fonts/LTSuperior-ExtraBold.otf
Normal file
Binary file not shown.
BIN
src/Fonts/LTSuperior-ExtraLight.otf
Normal file
BIN
src/Fonts/LTSuperior-ExtraLight.otf
Normal file
Binary file not shown.
BIN
src/Fonts/LTSuperior-Light.otf
Normal file
BIN
src/Fonts/LTSuperior-Light.otf
Normal file
Binary file not shown.
BIN
src/Fonts/LTSuperior-Medium.otf
Normal file
BIN
src/Fonts/LTSuperior-Medium.otf
Normal file
Binary file not shown.
Reference in New Issue
Block a user