diff --git a/.gitignore b/.gitignore index 22e9802..4451e89 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /compile/main .vscode -obj \ No newline at end of file +obj +dreeAlias.sh \ No newline at end of file diff --git a/Makefile b/Makefile index f1cc3bb..15b9f0f 100644 --- a/Makefile +++ b/Makefile @@ -37,8 +37,9 @@ $(DIRECTORIES): # Target to run the program run: $(EXECUTABLE) - $(EXECUTABLE) + $(EXECUTABLE) $(ARGS) # Clean target clean: rm -rf $(OBJDIR) $(EXECUTABLE) + diff --git a/dree.sh b/dree.sh new file mode 100755 index 0000000..7a454fe --- /dev/null +++ b/dree.sh @@ -0,0 +1,2 @@ +script_dir="$(dirname "$0")" +make run -C "$script_dir" ARGS="$(pwd) $1" diff --git a/dump.txt b/dump.txt new file mode 100644 index 0000000..45ed3a8 --- /dev/null +++ b/dump.txt @@ -0,0 +1,3 @@ +# #!/bin/bash +# make run -C /home/ujjwal/Desktop/crawlir ARGS="$(pwd) $1" + diff --git a/readme.md b/readme.md index 45deb32..3601285 100644 --- a/readme.md +++ b/readme.md @@ -8,6 +8,31 @@ Say no to bulky file managers with Dree. **Important:** This project is a work in progress and is not intended for production use at this time. It is undergoing active development, and changes, improvements, and bug fixes are being made frequently. +# Installation[Linux] + +To run the Directory Tree Visualizer project, follow these steps: + +1. Ensure you have C++17 compiler and development environment set up on your linux or mac system +2. Clone the project repository to your local machine. + +```shell +git clone https://github.com/ujjwall-R/Dree +cd Dree +``` + +Add path to `dree.sh` in `~/.bashrc` as: + +``` +alias dree='path/to/project/dree.sh' +``` + +## Run [example] + +``` +dree 3 +``` + +# Development ## How to Run [Development] diff --git a/src/controller/DirectoryGraph.cpp b/src/controller/DirectoryGraph.cpp index 4b7451a..6e55b74 100644 --- a/src/controller/DirectoryGraph.cpp +++ b/src/controller/DirectoryGraph.cpp @@ -40,7 +40,7 @@ void DirectoryGraph::TraverseDirectoriesDFS(DirectoryNode *node, long long depth } } -void DirectoryGraph::PrintGraph(DirectoryNode *node, long long depth, long long currentDepth, bool isLastChild, long long mask) +void DirectoryGraph::PrintGraphDFS(DirectoryNode *node, long long depth, long long currentDepth, bool isLastChild, long long mask) { if (currentDepth == depth) return; @@ -62,11 +62,11 @@ void DirectoryGraph::PrintGraph(DirectoryNode *node, long long depth, long long { mask = mask | (1ll << (currentDepth + 1)); } - PrintGraph(child, depth, currentDepth + 1, i == node->children.size() - 1, mask); + PrintGraphDFS(child, depth, currentDepth + 1, i == node->children.size() - 1, mask); } } -void DirectoryGraph::PrintGraph(DirectoryNode *node, long long depth) +void DirectoryGraph::PrintGraphDFS(DirectoryNode *node, long long depth) { - this->PrintGraph(node, depth, 0, true, 1); + this->PrintGraphDFS(node, depth, 0ll, true, 1ll); } \ No newline at end of file diff --git a/src/controller/DirectoryGraph.h b/src/controller/DirectoryGraph.h index 408157c..c173451 100644 --- a/src/controller/DirectoryGraph.h +++ b/src/controller/DirectoryGraph.h @@ -12,12 +12,12 @@ class DirectoryGraph { public: DirectoryNode *BuildGraph(const string &directoryName, long long depth); - void PrintGraph(DirectoryNode *node, long long depth); + void PrintGraphDFS(DirectoryNode *node, long long depth); private: bool isDirectory(const std::string &pathStr); void TraverseDirectoriesDFS(DirectoryNode *node, long long depth, long long currentDepth = 0); - void PrintGraph(DirectoryNode *node, long long depth, long long currentDepth, bool isLastChild, long long mask); + void PrintGraphDFS(DirectoryNode *node, long long depth, long long currentDepth, bool isLastChild, long long mask); }; #endif diff --git a/src/main.cpp b/src/main.cpp index 13ac231..a330b53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,12 +6,26 @@ using namespace std; -int main() +int main(int argc, char *argv[]) { - long long depth = 3; // should not be more than 60 - auto currentPath = filesystem::current_path(); + if (argc != 3) + { + cout << "Missing args" << std::endl; + return 1; + } + string currentPath = argv[1]; + filesystem::path directoryPath(currentPath); + int depth = stoi(argv[2]); + + // TODO:add check to prevent overflow + if (depth >= 60) + { + cout << "mask overflow!!\n"; + return 1; + } + DirectoryGraph builder; auto root = builder.BuildGraph(currentPath, depth); - builder.PrintGraph(root, depth); + builder.PrintGraphDFS(root, depth); return 0; }