Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new features to get list general user folders and files in windows system #13

Merged
merged 10 commits into from
Mar 30, 2023
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@

# Changelog

## v0.1.3
## v0.1.4

### BScan

This is the latest version introduces the use of the module and its features.

## v0.1.4 [2023-03-30]

### Features

- [#12](https://github.com/BarcaWebCloud/bscan/pull/12): New features for Windows OS. Gratitude @ahsouza!


### Release Notes


Add features for **Windows** platform:

- **List Program Files and Folders, Personal Documents & Public** [only Windows on moment]
- **List Recent Items, Home Directory, Downloads, Musics, Videos/Images & Searched Items** [only Windows on moment]


## v0.1.3 [2023-03-28]

### Features
Expand All @@ -31,7 +47,6 @@ Add features for **Windows** platform:




## v0.1.2 [2023-03-18]

### Features
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ It is necessary that you have installed the programs below to use **BSCAN** in d
- [MinGW/GCC](https://www.mingw-w64.org)
- [Clang](https://clang.llvm.org)
- [Intel](https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html)
- [Visual](https://visualstudio.microsoft.com/vs/features/cplusplus)
- [Visual (suggested)](https://visualstudio.microsoft.com/vs/features/cplusplus)
- [Code Block](https://wiki.codeblocks.org/index.php/Installing_a_supported_compiler)
- [Cygwin](http://www.cygwin.org)
- [Small Device](https://sdcc.sourceforge.net)
Expand Down
42 changes: 42 additions & 0 deletions include/swares/scan_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ namespace bscan {
std::string uptime();
std::string homedir();
std::string recentitems();
std::string programfiles();
std::string documents();
std::string personaldocuments();
std::string publicdocuments();
std::string searcheseverywhere();
std::string desktop();
std::string downloads();
std::string musics();
std::string videos();
std::string startmenu();
std::string imagescam();
std::string imagessaved();
std::string images();
std::string historycommands();
std::string pkgs();
std::string user();
std::string log();
Expand All @@ -54,6 +68,20 @@ namespace bscan {
static std::string getUptime();
static std::string listHomeDir();
static std::string listRecentItems();
static std::string listProgramFiles();
static std::string listDocuments();
static std::string listPersonalDocuments();
static std::string listPublicDocuments();
static std::string listSearchesEverywhere();
static std::string listDesktop();
static std::string listDownloads();
static std::string listMusics();
static std::string listVideos();
static std::string listStartMenu();
static std::string getImagesCAM();
static std::string getImagesSaved();
static std::string getImages();
static std::string getHistoryCommands();
static std::string getPkgs();
static std::string getUser();
static std::string getLog();
Expand All @@ -73,6 +101,20 @@ namespace bscan {
std::string _uptime;
std::string _homedir;
std::string _recentitems;
std::string _programfiles;
std::string _documents;
std::string _personaldocuments;
std::string _publicdocuments;
std::string _searcheseverywhere;
std::string _desktop;
std::string _downloads;
std::string _musics;
std::string _videos;
std::string _startmenu;
std::string _imagescam;
std::string _imagessaved;
std::string _images;
std::string _historycommands;
std::string _pkgs;
std::string _user;
std::string _log;
Expand Down
22 changes: 12 additions & 10 deletions include/utils/directory.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ std::string getCurrentDir(void) {
return currentDir;
}

std::string getFoldersAndFilesInCurrentDir(void) {
struct dirent *d;

std::string listDir(char* path) {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);

DIR *dr;
dr = opendir(".");
std::string res;
if(dr!=NULL) {
for(d=readdir(dr); d!=NULL; d=readdir(dr)) {
res+= std::string(d->d_name) + std::string("\n");
struct dirent *en;
dr = opendir(path);
std::string listFilesAndFolders;
if (dr) {
while ((en = readdir(dr)) != NULL) {
listFilesAndFolders += std::string("\n") + std::string(en->d_name);
}
closedir(dr);
}
else
return "<null>";
return res;
return std::string(listFilesAndFolders);
}
151 changes: 116 additions & 35 deletions src/libs/info/windows/scan_os.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************************

* Copyright (C) 2021 - 2023, Barca, Inc.

* Email: <opensource@barca.com> GitHub: @BarcaWebCloud.
Expand Down Expand Up @@ -33,12 +33,12 @@
#include <dirent.h>
#include <sys/types.h>


#define STATUS_SUCCESS 0x00000000

#include "swares/scan_os.h"
#include "utils/directory.h"
#include "utils/string.h"
#include <utils/subprocess.h>
#include "utils/subprocess.h"

namespace bscan {

Expand Down Expand Up @@ -319,52 +319,133 @@ namespace bscan {
return std::string(lower(username));
}

std::string OS::listDesktop() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(content));
}

std::string OS::listHomeDir() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content = 0;
char* content;
content = getenv("USERPROFILE");
if (content != 0) {
DIR *dr;
struct dirent *en;
dr = opendir(content);
std::string listFilesAndFolders;
if (dr) {
while ((en = readdir(dr)) != NULL) {
listFilesAndFolders += std::string("\n") + std::string(en->d_name);
}
closedir(dr);
}
return std::string(listFilesAndFolders);
}
return std::string(listDir(content));
}

return std::string("unknow");
std::string OS::listRecentItems() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\AppData\\Roaming\\Microsoft\\Windows\\Recent")));
}

std::string OS::listProgramFiles() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("HOMEDRIVE");
return std::string(listDir(strcat(content, "\\Program Files")));
}

std::string OS::listRecentItems() {
std::string OS::listDocuments() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content = 0;
const char *content2 = "\\AppData\\Roaming\\Microsoft\\Windows\\Recent";
char* content;
content = getenv("USERPROFILE");
if (content != 0) {
DIR *dr;
struct dirent *en;
dr = opendir(strcat(content, content2));
std::string listFilesAndFolders;
if (dr) {
while ((en = readdir(dr)) != NULL) {
listFilesAndFolders += std::string("\n") + std::string(en->d_name);
}
closedir(dr);
}
return std::string(listFilesAndFolders);
}
return std::string(listDir(strcat(content, "\\AppData\\Roaming\\Microsoft\\Windows\\Libraries\\Documents.library-ms")));
}

std::string OS::listPersonalDocuments() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\Documents")));
}

std::string OS::listPublicDocuments() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("HOMEDRIVE");
return std::string(listDir(strcat(content, "\\Users\\Public\\Documents")));
}

std::string OS::listDownloads() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\Downloads")));
}

std::string OS::listMusics() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\AppData\\Roaming\\Microsoft\\Windows\\Libraries\\Music.library-ms")));
}

std::string OS::listVideos() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\AppData\\Roaming\\Microsoft\\Windows\\Libraries\\Videos.library-ms")));
}

std::string OS::listSearchesEverywhere() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\Searches\\Everywhere.search-ms")));
}

return std::string("unknow");
std::string OS::listStartMenu() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs")));
}

std::string OS:: getImagesCAM() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\AppData\\Roaming\\Microsoft\\Windows\\Libraries\\CameraRoll.library-ms")));
}

std::string OS:: getImagesSaved() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\AppData\\Roaming\\Microsoft\\Windows\\Libraries\\SavedPictures.library-ms")));
}

std::string OS:: getImages() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\AppData\\Roaming\\Microsoft\\Windows\\Libraries\\Pictures.library-ms")));
}

std::string OS:: getHistoryCommands() {
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
char* content;
content = getenv("USERPROFILE");
return std::string(listDir(strcat(content, "\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadLine")));
}

std::string OS::getEnvVariables() {

Expand Down