احم, بما اني طبعا لم استخدم السي بلص بلص من زمان, لازم اراجع بعض الامور :)
محاولتي الاولية لاضافة check فشلت نوعا ما,
قمت بتحرير بعض الملفات و اضافة بعض الاكواد, لكي اريكم هذه الاكواد, انفذ الامر git diff و سيخرج لي مقارنة diff بين الكود الحالي و بين اخر ايداع commit
C:\code\encat>git diff
diff --git a/EncAT.h b/EncAT.h
index cac09a5..57acbbd 100644
--- a/EncAT.h
+++ b/EncAT.h
@@ -11,6 +11,10 @@
namespace EncAT{
+ class IOFail
+ {
+ };
+
inline void EncDec( char* memBlock, size_t blockSize, char* password, size_t passSize ){
for( size_t C = 0; C < blockSize; C++ )
@@ -33,6 +37,10 @@ namespace EncAT{
passFile.open( passPath, std::ios::binary );
encFile.open( encFilePath, std::ios::binary );
+ if (srcFile.fail()) throw new IOFail();
+ if (passFile.fail()) throw new IOFail();
+ if (encFile.fail()) throw new IOFail();
+
//
srcFile.seekg( 0, std::ios::end );
srcSize = srcFile.tellg();
diff --git a/main.cpp b/main.cpp
index 0fdd7d2..ed4cfec 100644
--- a/main.cpp
+++ b/main.cpp
@@ -126,8 +126,10 @@ int main()
desPath = srcPath;
replaceExt( desPath, "dec" );
+ try
+ {
// Start; Decryption Process
- EncAT::EncDecFile( srcPath.c_str(), passPath.c_str(), desPath.c_str() );
+ EncAT::EncDecFile( srcPath.c_str(), passPath.c_str(), desPath.c_str() );
// End;
std::cout << con::clr; // Clear the Intro Screen
@@ -137,9 +139,17 @@ int main()
<< con::fg_yellow
<< " EncAT has created one file in the same folder of the encrypte file :" << std::endl << std::endl
- << "\t.dec = Decrypted file" << std::endl << std::endl
+ << "\t.dec = Decrypted file" << std::endl << std::endl;
- << con::fg_gray
+ }
+ catch(EncAT::IOFail ex)
+ {
+ std::cout << std::endl << con::fg_red << "\t ---- I/O Error ---- \t" << std::endl
+ << con::fg_yellow
+ << " EncAt could not read the file(s) specified" << std::endl << std::endl;
+ }
+
+ std::cout << con::fg_gray
<< "press any key to continue...";
// Pause
@@ -165,4 +175,4 @@ int main()
std::cin.get();
return 0;
-}
\ No newline at end of file
+}
C:\code\encat>طبعا الـ output يمرر عن طريق less
يمكن يكون غير مفهوم تماما لغير اللينكسيين (!!) لكنه بسيط, الاسطر اللي عليها - هي الاسطر اللتي حذفت, و الاسطر اللي عليها + هي الاسطر اللتي اضيفت. طبعا لو تم نقل سطر من مكان الى اخر سيظهر انه حذف من مكان و اضيف الى مكان.
الان, الكود لا يعمل بشكل مضبوط, و لكني مع ذلك ساعمل commit
لكن قبل ذلك:
C:\code\encat>git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: EncAT.h # modified: main.cpp # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # Debug/ # EncAT.ncb # EncAT.sln # EncAT.vcproj # EncAT.vcproj.Toshiba.aljudy.user # hello.atp # hello.enc # mop.dec # random.atp # random.dec # random.enc no changes added to commit (use "git add" and/or "git commit -a") C:\code\encat>
احيانا اقوم بامر status من حين لاخر فقط لأتاكد ما هي الملفات اللتي تغيرت
و الان لعمل commit يجب اولا ان اضيف الملفات اللتي تم تغييرها
يمكن ان يتم ذلك عن طريق:
git add main.cpp
git add encat.h
و لكن يمكن ايضا اضافة الخيار -a الى الامر commit لكي يقوم بهذا العملية تلقائيا للملفات اللتي اضفناها في وقت سابق
C:\code\encat>git commit -a -m"Trying to handle case where files don't exist, doesn't work yet (compiles but fails to catch the error)" [master 9c0f45f] Trying to handle case where files don't exist, doesn't work yet (compiles but fails to catch the error) 2 files changed, 22 insertions(+), 4 deletions(-) C:\code\encat>
يمكن الان ان انظر الى الـ log
C:\code\encat>git log commit 9c0f45fe70916d328acf16d50ff02a5240fab3f5 Author: hasen j <hasan.aljudy@gmail.com> Date: Thu Jun 4 23:50:07 2009 -0600 Trying to handle case where files don't exist, doesn't work yet (compiles but fails to catch the error) commit 618b61a4c1f0d67c8cb7949ea15fd86ef794b582 Author: hasen j <hasan.aljudy@gmail.com> Date: Thu Jun 4 22:17:15 2009 -0600 Initial commit C:\code\encat>
اعتقد انني عرفت المشكلة .. الـ exception اللذي كنت ارميه كان بصيغة new IOFail() يعني مؤشر, و لكن حين امسكه استخدم IOFail ex بدون مؤشر :P
قمت بتغيير بسيط, و الان اذا قمت بادخال ملف غير موجود في حوار الـ Decrypt سوف يخرج لي رسالة خطأ
C:\code\encat>git diff
diff --git a/EncAT.h b/EncAT.h
index 57acbbd..5ba57c2 100644
--- a/EncAT.h
+++ b/EncAT.h
@@ -37,9 +37,9 @@ namespace EncAT{
passFile.open( passPath, std::ios::binary );
encFile.open( encFilePath, std::ios::binary );
- if (srcFile.fail()) throw new IOFail();
- if (passFile.fail()) throw new IOFail();
- if (encFile.fail()) throw new IOFail();
+ if (srcFile.fail()) throw IOFail();
+ if (passFile.fail()) throw IOFail();
+ if (encFile.fail()) throw IOFail();
//
srcFile.seekg( 0, std::ios::end );بعدها قمت بايداع الكود:
C:\code\encat>git commit -a -m"IOCheck works now for Decrypt dialoge"
الـ log الان شكله هكذا:
C:\code\encat>git log commit 1b21f0ac570ed2098736cec709e78f217b04f898 Author: hasen j <hasan.aljudy@gmail.com> Date: Thu Jun 4 23:57:53 2009 -0600 IOCheck works now for Decrypt dialoge commit 9c0f45fe70916d328acf16d50ff02a5240fab3f5 Author: hasen j <hasan.aljudy@gmail.com> Date: Thu Jun 4 23:50:07 2009 -0600 Trying to handle case where files don't exist, doesn't work yet (compiles but fails to catch the error) commit 618b61a4c1f0d67c8cb7949ea15fd86ef794b582 Author: hasen j <hasan.aljudy@gmail.com> Date: Thu Jun 4 22:17:15 2009 -0600 Initial commit C:\code\encat>


