Skip to content

Commit

Permalink
Merge pull request #4 from rounnus/dev
Browse files Browse the repository at this point in the history
Optimazitions and add a new option.
  • Loading branch information
constarg authored Sep 4, 2021
2 parents 1225620 + 4fd31e6 commit 4b5cd8f
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 340 deletions.
33 changes: 12 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(File_Sorter_Core C)

set(CMAKE_C_STANDARD 99)

add_executable(file-sorter main.c tools/logger.c tools/include/log/logger.h tools/config_parser.c tools/include/config/config_parser.h src/manager.c src/include/manager.h)
add_executable(file-sorter main.c tools/logger.c tools/include/log/logger.h tools/config_parser.c tools/include/config/config_parser.h src/manager.c src/include/manager.h tools/include/mem.h)

include_directories(
src/include
Expand All @@ -12,47 +12,38 @@ include_directories(

set(GCC_COVERAGE_COMPILE_FLAGS "-pthread")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")

file(MAKE_DIRECTORY /home/$ENV{USER}/.local/share/file_sorter/)

message("/home/$ENV{USER}/.local/share/file_sorter/ OK")

file(MAKE_DIRECTORY /home/$ENV{USER}/.local/share/file_sorter/config/)

message("/home/$ENV{USER}/.local/share/file_sorter/config/ OK")
file(MAKE_DIRECTORY /home/$ENV{USER}/default_sorter_path/)

message("/home/$ENV{USER}/default_sorter_path/ OK")
file(MAKE_DIRECTORY config/)

message("config/ OK")
file(MAKE_DIRECTORY service/)

message("service/ OK")
file(MAKE_DIRECTORY autostart/)
message("autostart/ OK")

if (EXISTS /home/$ENV{USER}/.config/systemd/)
message("/home/$ENV{USER}/.config/systemd/ OK")
if (EXISTS /home/$ENV{USER}/.config/systemd/user/)
message("/home/$ENV{USER}/.config/systemd/user/ OK")
else()
else ()
file(MAKE_DIRECTORY /home/$ENV{USER}/.config/systemd/user/)
message("/home/$ENV{USER}/.config/systemd/user/ OK")
endif()
else()
endif ()
else ()
file(MAKE_DIRECTORY /home/$ENV{USER}/.config/systemd/)
message("/home/$ENV{USER}/.config/systemd/ OK")
file(MAKE_DIRECTORY /home/$ENV{USER}/.config/systemd/user/)
message("/home/$ENV{USER}/.config/systemd/user/ OK")
endif()
endif ()

file(WRITE config/config.conf
[basic_config]\n
checkInterval\ 3000\n
parseInterval\ 5000\n
debugLog\ 0\n
defaultDirPath\ /home/$ENV{USER}/default_sorter_path/\n
check_interval\ 3000\n
parse_interval\ 5000\n
debug_log\ 0\n
default_dir_path\ /home/$ENV{USER}/default_sorter_path/\n
enable_default_path\ 1\n
\n
[check]\n
\n
Expand Down
42 changes: 28 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
# Introduction
This program transfers all files outside of folders
to the specific folders to which they belong.

This program transfers all files outside of folders to the specific folders to which they belong.

# Download & Build
First download the program from github and go to the File-Sorter-Core folder.

First download the program from GitHub and go to the File-Sorter-Core folder.

```
% git clone https://github.com/rounnus/File-Sorter-Core.git
% cd File-Sorter-Core/
```
After installation the program must be built. In order to build the program, the following instructions must be followed.<br>

After installation the program must be built. In order to build the program, the following instructions must be
followed.<br>

```
% mkdir build
% cd build/
% cmake ../
% make
% sudo make install
```

After this the program will be installed and ready to run.

# Config
The program gets the information it needs from a config file, which is like the following

The program gets the information it needs from a config file, which is like the following

```
[basic_config]
checkInterval 3000
parseInterval 5000
debugLog 0
defaultDirPath /home/username/default_sorter_path/
check_interval 3000
parse_interval 5000
debug_log 0
default_dir_path /home/username/default_sorter_path/
[check]
Expand All @@ -37,35 +43,43 @@ defaultDirPath /home/username/default_sorter_path/
[done_targets]
```

The information is as follows.<br>

Field | Description
---------|--------------
`checkInterval` | The time between checks (for new files etc).
`parseInterval` | The time to read the config file again for any changes.
`debugLog` | For debugging. To enter debug mode, the value of the debugLog field must be changed to 1.
`defaultDirPath` | If a file is found outside of a folder and no specific location has been specified to which it should be moved, then it will go to defaultDirPath.
`check_interval` | The time between checks (for new files etc).
`parse_interval` | The time to read the config file again for any changes.
`debug_log` | For debugging. To enter debug mode, the value of the debugLog field must be changed to 1.
`default_dir_path` | If a file is found outside of a folder and no specific location has been specified to which it should be moved, then it will go to default_dir_path.
`enable_default_path` | If this option is enabled, no files are transferred to the default folder.
`[check]` | This field includes all locations where the program will look for files. Each location that enters this field must be entered before `[done_check]`.
`[targets]` | This field contains all the file extensions and all the locations that these files should be sent to. Each line in this field consists of two elements that are separated by a space. The first element is the extension of the file and the second is the location where this file should be sent. Also each new line must be entered before `[done_targets]`.

An example of `[check]`:<br>

```
[check]
/home/username/
/home/username/Desktop/
...
[done_check]
```

An example of `[targets]`:<br>

```
[targets]
.py /home/username/Documents/py/
.cpp /home/username/Documents/cpp/
...
[done_targets]
```
In the example above the first part consists of the extensions `.py` and `.cpp` and the second part of the locations `/home/username/ Documents/py/` and `/home/username/Documents/cpp/`.

In the example above the first part consists of the extensions `.py` and `.cpp` and the second part of the
locations `/home/username/ Documents/py/` and `/home/username/Documents/cpp/`.

# Service

The program can be run using `systemd`. To start the program from `systemd` the following must be performed.<br>
``` systemctl --user start file-sorter```
9 changes: 5 additions & 4 deletions config/config.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[basic_config]
checkInterval 3000
parseInterval 5000
debugLog 0
defaultDirPath /home/rounnus/default_sorter_path/
check_interval 3000
parse_interval 5000
debug_log 0
default_dir_path /home/rounnus/default_sorter_path/
enable_default_path 1

[check]

Expand Down
1 change: 0 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


int main() {

run();
return 0;
}
Loading

0 comments on commit 4b5cd8f

Please sign in to comment.