summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-06-27 17:53:20 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-06-27 17:53:20 +0300
commit7967ad2f48635a060a75c469315b6f3315b15a7e (patch)
treef3d13ea275100a42aa29369b974761bc7a0dd3ed
parentFailprove config.cpp. (diff)
downloadidfetch-7967ad2f48635a060a75c469315b6f3315b15a7e.tar.gz
idfetch-7967ad2f48635a060a75c469315b6f3315b15a7e.tar.bz2
idfetch-7967ad2f48635a060a75c469315b6f3315b15a7e.zip
Failprove tui.cpp and log errors to error.log
-rw-r--r--segget/settings.cpp4
-rw-r--r--segget/tui.cpp162
2 files changed, 119 insertions, 47 deletions
diff --git a/segget/settings.cpp b/segget/settings.cpp
index 613bcdb..e4103e4 100644
--- a/segget/settings.cpp
+++ b/segget/settings.cpp
@@ -9,8 +9,8 @@ void Tsettings::load_from_conf_file(){
conf.set(error_log_file, "logs", "error_log_file");
conf.set(debug_log_file, "logs", "debug_log_file");
- conf.set(distfiles_dir, "folders", "distfiles_dir");
- conf.set(segments_dir, "folders", "segments_dir");
+ conf.set(distfiles_dir, "folders", "distfiles_dir");
+ conf.set(segments_dir, "folders", "segments_dir");
// log("segments_dir set to:"+segments_dir);
conf.set(max_connection_num_per_distfile, "distfiles", "max_connection_num_per_distfile",1,20);
diff --git a/segget/tui.cpp b/segget/tui.cpp
index 12c7afb..0b7b260 100644
--- a/segget/tui.cpp
+++ b/segget/tui.cpp
@@ -1,6 +1,10 @@
#include "tui.h"
extern Tsettings settings;
+const uint CONNECTION_LINES=5;
+void msg(uint y, uint x, string msg_text);
+void error_log_no_msg(string error_msg_text);
+
template<typename T> string toString(T t)
{
stringstream s;
@@ -18,76 +22,144 @@ template<typename T> string field(string prefix,T t, int width)
return s2.str();
}
-string set_width(string input_string, int width){
- std::stringstream s;
- s.width(width);
- s << input_string;
- return s.str();
-}
-
-const uint CONNECTION_LINES=5;
-void msg(uint y, uint x, string msg_text);
-
void msg(uint y, uint x, string msg_text){
- move(y,x);
- string ready_msg_text=msg_text+" ";
- printw(ready_msg_text.c_str());
- refresh();
+ move(y,x);
+ string ready_msg_text=msg_text+" ";
+ printw(ready_msg_text.c_str());
+ refresh();
}
void msg_connecting(uint connection_num, uint distfile_num, uint segment_num, string msg_text){
- msg(connection_num*CONNECTION_LINES+1,0,"DF#"+toString(distfile_num)+" Seg#"+toString(segment_num)+" "+msg_text);
+ try{
+ msg(connection_num*CONNECTION_LINES+1,0,"DF#"+toString(distfile_num)+" Seg#"+toString(segment_num)+" "+msg_text);
+ }
+ catch(...)
+ {
+ error_log_no_msg("Error in tui.cpp: msg_connecting()");
+ }
}
void msg_segment_progress(uint connection_num, uint segment_num, uint try_num, ulong dld_bytes, ulong total_bytes, ulong speed){
- int percent=dld_bytes*100/total_bytes;
- if (speed<1000)
- msg(connection_num*CONNECTION_LINES,0,
- field("[",connection_num,2)+"]"
- +field(" Segment:",segment_num, 5)
- +field(" Try:",try_num,4)
- +field(" Bytes:",dld_bytes,7)
- +field(" / ",total_bytes,7)
- +field(" = ",percent,3)+"%%"
- +field(" Speed:",speed,7)+" b/s");
- else
- msg(connection_num*CONNECTION_LINES,0,
- field("[",connection_num,2)+"]"
- +field(" Segment:",segment_num, 5)
- +field(" Try:",try_num,4)
- +field(" Bytes:",dld_bytes,7)
- +field(" / ",total_bytes,7)
- +field(" = ",percent,3)+"%%"
- +field(" Speed:",speed/1000,7)+" Kb/s");
+ try{
+ int percent=dld_bytes*100/total_bytes;
+ if (speed<1000)
+ msg(connection_num*CONNECTION_LINES,0,
+ field("[",connection_num,2)+"]"
+ +field(" Segment:",segment_num, 5)
+ +field(" Try:",try_num,4)
+ +field(" Bytes:",dld_bytes,7)
+ +field(" / ",total_bytes,7)
+ +field(" = ",percent,3)+"%%"
+ +field(" Speed:",speed,7)+" b/s");
+ else
+ msg(connection_num*CONNECTION_LINES,0,
+ field("[",connection_num,2)+"]"
+ +field(" Segment:",segment_num, 5)
+ +field(" Try:",try_num,4)
+ +field(" Bytes:",dld_bytes,7)
+ +field(" / ",total_bytes,7)
+ +field(" = ",percent,3)+"%%"
+ +field(" Speed:",speed/1000,7)+" Kb/s");
+ }
+ catch(...)
+ {
+ error_log_no_msg("Error in tui.cpp: msg_segment_progress()");
+ }
}
void msg_status1(uint connection_num, uint segment_num, string msg_text){
- msg(connection_num*CONNECTION_LINES+2,0,"Seg#"+toString(segment_num)+" "+msg_text);
+ try{
+ msg(connection_num*CONNECTION_LINES+2,0,"Seg#"+toString(segment_num)+" "+msg_text);
+ }
+ catch(...)
+ {
+ error_log_no_msg("Error in tui.cpp: msg_status1()");
+ }
}
void msg_status2(uint connection_num, string msg_text){
- msg(connection_num*CONNECTION_LINES+3,0,msg_text);
+ try{
+ msg(connection_num*CONNECTION_LINES+3,0,msg_text);
+ }
+ catch(...)
+ {
+ error_log_no_msg("Error in tui.cpp: msg_status2()");
+ }
}
void msg_error(string error_text){
- msg(20,0, error_text);
+ try{
+ msg(20,0, error_text);
+ }
+ catch(...)
+ {
+ error_log_no_msg("Error in tui.cpp: msg_error()");
+ }
}
void msg_total(string msg_text){
- msg(30,0,msg_text);
+ try{
+ msg(30,0,msg_text);
+ }
+ catch(...)
+ {
+ error_log_no_msg("Error in tui.cpp: msg_total()");
+ }
}
void log(string log_msg_text){
- ofstream file ((settings.logs_dir+"/"+settings.general_log_file).c_str(), ios::app);
- file << log_msg_text << endl;
- file.close();
msg(31,0, "LOG:"+log_msg_text);
+ ofstream file;
+ file.exceptions (ofstream::failbit | ofstream::badbit);
+ try{
+ file.open((settings.logs_dir+"/"+settings.general_log_file).c_str(), ios::app);
+ }
+ catch(...){
+ error_log("Error opening "+settings.logs_dir+"/"+settings.general_log_file+".");
+ return;
+ }
+ try{
+ file << log_msg_text << endl;
+ file.close();
+ }
+ catch(...){
+ error_log("Error while writing "+settings.logs_dir+"/"+settings.general_log_file+".");
+ return;
+ }
}
void debug(string debug_msg_text){
- ofstream file ((settings.logs_dir+"/"+settings.debug_log_file).c_str(), ios::app);
- file << debug_msg_text << endl;
- file.close();
msg(32,0, "DEBUG:"+debug_msg_text);
+ ofstream file;
+ file.exceptions (ofstream::failbit | ofstream::badbit);
+ try{
+ file.open((settings.logs_dir+"/"+settings.debug_log_file).c_str(), ios::app);
+ }
+ catch(...){
+ error_log("Error opening "+settings.logs_dir+"/"+settings.debug_log_file+".");
+ return;
+ }
+ try{
+ file << debug_msg_text << endl;
+ file.close();
+ }
+ catch(...){
+ error_log("Error while writing "+settings.logs_dir+"/"+settings.debug_log_file+".");
+ return;
+ }
}
+
+void error_log_no_msg(string error_msg_text){
+ ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app);
+ file << error_msg_text << endl;
+ file.close();
+}
+
void error_log(string error_msg_text){
ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app);
file << error_msg_text << endl;
file.close();
- msg(33,0, "ERROR:"+error_msg_text);
+ try{
+ msg(33,0, "ERROR:"+error_msg_text);
+ }
+ catch(...)
+ {
+ error_log_no_msg("Error calling msg() in tui.cpp: error_log()");
+ }
+
} \ No newline at end of file