added internet connection detection

This commit is contained in:
max mustermann 2019-05-05 18:50:10 +02:00
parent 97469e3e43
commit 004ca7c62c
4 changed files with 123 additions and 92 deletions

155
.idea/workspace.xml generated
View File

@ -14,9 +14,7 @@
</configurations> </configurations>
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="59c80f39-2468-4db0-9afd-14b8acdbffed" name="Default Changelist" comment="deleted cmake files"> <list default="true" id="59c80f39-2468-4db0-9afd-14b8acdbffed" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/Logger.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/Logger.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" /> <change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/API.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/src/API.cpp" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/API.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/src/API.cpp" afterDir="false" />
@ -36,14 +34,20 @@
<component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" /> <component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" />
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90">
<caret line="6" column="40" lean-forward="true" selection-start-line="6" selection-start-column="40" selection-end-line="6" selection-end-column="40" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/API.h"> <entry file="file://$PROJECT_DIR$/src/API.h">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="210"> <state relative-caret-position="195">
<caret line="14" column="124" selection-start-line="14" selection-start-column="124" selection-end-line="14" selection-end-column="124" /> <caret line="14" column="124" selection-start-line="14" selection-start-column="124" selection-end-line="14" selection-end-column="124" />
<folding>
<element signature="e#95#112#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -51,8 +55,11 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/API.cpp"> <entry file="file://$PROJECT_DIR$/src/API.cpp">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="281"> <state relative-caret-position="45">
<caret line="44" column="17" selection-start-line="44" selection-start-column="17" selection-end-line="44" selection-end-column="17" /> <caret line="3" selection-start-line="3" selection-end-line="3" />
<folding>
<element signature="e#40#56#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -65,8 +72,8 @@
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main.cpp"> <entry file="file://$PROJECT_DIR$/src/main.cpp">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289"> <state relative-caret-position="240">
<caret line="29" column="41" lean-forward="true" selection-start-line="29" selection-start-column="41" selection-end-line="29" selection-end-column="41" /> <caret line="16" column="69" selection-start-line="16" selection-start-column="69" selection-end-line="16" selection-end-column="69" />
<folding> <folding>
<element signature="e#0#19#0" expanded="true" /> <element signature="e#0#19#0" expanded="true" />
</folding> </folding>
@ -83,7 +90,7 @@
<entry file="file://$PROJECT_DIR$/src/Logger.cpp"> <entry file="file://$PROJECT_DIR$/src/Logger.cpp">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="555"> <state relative-caret-position="555">
<caret line="37" column="38" lean-forward="true" selection-start-line="37" selection-start-column="38" selection-end-line="37" selection-end-column="38" /> <caret line="37" column="38" selection-start-line="37" selection-start-column="38" selection-end-line="37" selection-end-column="38" />
<folding> <folding>
<element signature="e#40#58#0" expanded="true" /> <element signature="e#40#58#0" expanded="true" />
</folding> </folding>
@ -96,11 +103,6 @@
<provider selected="true" editor-type-id="text-editor" /> <provider selected="true" editor-type-id="text-editor" />
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/cmake-build-debug/dynurefresher.log">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Logger.h"> <entry file="file://$PROJECT_DIR$/src/Logger.h">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -130,12 +132,12 @@
<option value="$PROJECT_DIR$/API.h" /> <option value="$PROJECT_DIR$/API.h" />
<option value="$PROJECT_DIR$/main.cpp" /> <option value="$PROJECT_DIR$/main.cpp" />
<option value="$PROJECT_DIR$/API.cpp" /> <option value="$PROJECT_DIR$/API.cpp" />
<option value="$PROJECT_DIR$/CMakeLists.txt" />
<option value="$PROJECT_DIR$/.gitignore" /> <option value="$PROJECT_DIR$/.gitignore" />
<option value="$PROJECT_DIR$/src/API.cpp" />
<option value="$PROJECT_DIR$/src/Logger.h" /> <option value="$PROJECT_DIR$/src/Logger.h" />
<option value="$PROJECT_DIR$/src/main.cpp" />
<option value="$PROJECT_DIR$/src/Logger.cpp" /> <option value="$PROJECT_DIR$/src/Logger.cpp" />
<option value="$PROJECT_DIR$/src/API.cpp" />
<option value="$PROJECT_DIR$/CMakeLists.txt" />
<option value="$PROJECT_DIR$/src/main.cpp" />
</list> </list>
</option> </option>
</component> </component>
@ -160,12 +162,16 @@
<path> <path>
<item name="iprefresher" type="b2602c69:ProjectViewProjectNode" /> <item name="iprefresher" type="b2602c69:ProjectViewProjectNode" />
<item name="DynuIPRefresher" type="462c0819:PsiDirectoryNode" /> <item name="DynuIPRefresher" type="462c0819:PsiDirectoryNode" />
<item name="cmake-build-debug" type="462c0819:PsiDirectoryNode" /> <item name="src" type="462c0819:PsiDirectoryNode" />
</path> </path>
<path> <path>
<item name="iprefresher" type="b2602c69:ProjectViewProjectNode" /> <item name="iprefresher" type="b2602c69:ProjectViewProjectNode" />
<item name="DynuIPRefresher" type="462c0819:PsiDirectoryNode" /> <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
<item name="src" type="462c0819:PsiDirectoryNode" /> </path>
<path>
<item name="iprefresher" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
<item name="Header Search Paths" type="70bed36:NamedLibraryElementNode" />
</path> </path>
</expand> </expand>
<select /> <select />
@ -180,6 +186,7 @@
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" /> <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" /> <property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="settings.editor.selected.configurable" value="CLionExternalConfigurable" />
</component> </component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
@ -222,7 +229,7 @@
<workItem from="1556646880233" duration="656000" /> <workItem from="1556646880233" duration="656000" />
<workItem from="1556710548728" duration="6200000" /> <workItem from="1556710548728" duration="6200000" />
<workItem from="1557047487321" duration="761000" /> <workItem from="1557047487321" duration="761000" />
<workItem from="1557061811880" duration="5098000" /> <workItem from="1557061811880" duration="10758000" />
</task> </task>
<task id="LOCAL-00001" summary="edited api class and made it to work"> <task id="LOCAL-00001" summary="edited api class and made it to work">
<created>1557063528491</created> <created>1557063528491</created>
@ -245,11 +252,25 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1557063931807</updated> <updated>1557063931807</updated>
</task> </task>
<option name="localTasksCounter" value="4" /> <task id="LOCAL-00004" summary="added loggin methods">
<created>1557066938057</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1557066938057</updated>
</task>
<task id="LOCAL-00005" summary="log on error">
<created>1557067359327</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1557067359327</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers /> <servers />
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="17949000" /> <option name="totallyTimeSpent" value="23609000" />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="1919" y="0" width="1922" height="1081" extended-state="6" /> <frame x="1919" y="0" width="1922" height="1081" extended-state="6" />
@ -270,7 +291,7 @@
<window_info anchor="bottom" id="Terminal" order="9" /> <window_info anchor="bottom" id="Terminal" order="9" />
<window_info anchor="bottom" id="Event Log" order="10" side_tool="true" /> <window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
<window_info anchor="bottom" id="Version Control" order="11" /> <window_info anchor="bottom" id="Version Control" order="11" />
<window_info anchor="bottom" id="CMake" order="12" weight="0.32834226" /> <window_info anchor="bottom" id="CMake" order="12" weight="0.328125" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" /> <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@ -283,30 +304,15 @@
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="edited api class and made it to work" /> <MESSAGE value="edited api class and made it to work" />
<MESSAGE value="deleted cmake files" /> <MESSAGE value="deleted cmake files" />
<option name="LAST_COMMIT_MESSAGE" value="deleted cmake files" /> <MESSAGE value="added loggin methods" />
<MESSAGE value="log on error" />
<option name="LAST_COMMIT_MESSAGE" value="log on error" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/test.cpp" /> <entry file="file://$PROJECT_DIR$/test.cpp" />
<entry file="file://$PROJECT_DIR$/test.h" /> <entry file="file://$PROJECT_DIR$/test.h" />
<entry file="file://$PROJECT_DIR$/cmake_install.cmake" /> <entry file="file://$PROJECT_DIR$/cmake_install.cmake" />
<entry file="file://$PROJECT_DIR$/iprefresher.cbp" /> <entry file="file://$PROJECT_DIR$/iprefresher.cbp" />
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135">
<caret line="9" column="19" selection-start-line="9" selection-start-column="19" selection-end-line="9" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/API.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="210">
<caret line="14" column="124" selection-start-line="14" selection-start-column="124" selection-end-line="14" selection-end-column="124" />
<folding>
<element signature="e#95#112#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Hashmap.h"> <entry file="file://$PROJECT_DIR$/src/Hashmap.h">
<provider selected="true" editor-type-id="text-editor" /> <provider selected="true" editor-type-id="text-editor" />
</entry> </entry>
@ -317,13 +323,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/API.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="281">
<caret line="44" column="17" selection-start-line="44" selection-start-column="17" selection-end-line="44" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/out.myfile"> <entry file="file://$PROJECT_DIR$/cmake-build-debug/out.myfile">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15"> <state relative-caret-position="15">
@ -338,29 +337,57 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/CMakeCache.txt">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/ip.txt">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/dynurefresher.log">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/Logger.cpp"> <entry file="file://$PROJECT_DIR$/src/Logger.cpp">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="555"> <state relative-caret-position="555">
<caret line="37" column="38" lean-forward="true" selection-start-line="37" selection-start-column="38" selection-end-line="37" selection-end-column="38" /> <caret line="37" column="38" selection-start-line="37" selection-start-column="38" selection-end-line="37" selection-end-column="38" />
<folding> <folding>
<element signature="e#40#58#0" expanded="true" /> <element signature="e#40#58#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/dynurefresher.log">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195">
<caret line="13" column="31" selection-start-line="13" selection-start-column="31" selection-end-line="13" selection-end-column="31" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/ip.txt">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/API.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195">
<caret line="14" column="124" selection-start-line="14" selection-start-column="124" selection-end-line="14" selection-end-column="124" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/API.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" selection-start-line="3" selection-end-line="3" />
<folding>
<element signature="e#40#56#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/CMakeCache.txt">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90">
<caret line="6" column="40" lean-forward="true" selection-start-line="6" selection-start-column="40" selection-end-line="6" selection-end-column="40" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main.cpp"> <entry file="file://$PROJECT_DIR$/src/main.cpp">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289"> <state relative-caret-position="240">
<caret line="29" column="41" lean-forward="true" selection-start-line="29" selection-start-column="41" selection-end-line="29" selection-end-column="41" /> <caret line="16" column="69" selection-start-line="16" selection-start-column="69" selection-end-line="16" selection-end-column="69" />
<folding> <folding>
<element signature="e#0#19#0" expanded="true" /> <element signature="e#0#19#0" expanded="true" />
</folding> </folding>

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.14) cmake_minimum_required(VERSION 3.7)
project(iprefresher) project(iprefresher)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 11)
find_package(CURL REQUIRED) find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR}) include_directories(${CURL_INCLUDE_DIR})

View File

@ -7,8 +7,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <stdio.h> #include "curl/curl.h"
#include <curl/curl.h>
#include <sstream> #include <sstream>
#include "Hashmap.h" #include "Hashmap.h"

View File

@ -11,6 +11,12 @@ int main() {
std::string ip = api.request("https://api.ipify.org"); std::string ip = api.request("https://api.ipify.org");
if(ip == ""){
//no internet connection
logger.logToLogfile("[WARNING] no internet connection");
std::cout << "[WARNING] no internet connection" << std::endl;
}else{
std::string oldip = logger.readip(); std::string oldip = logger.readip();
if(oldip == ip){ if(oldip == ip){
@ -42,8 +48,7 @@ int main() {
logger.safeip(ip); logger.safeip(ip);
} }
}
return 0; return 0;
} }