forked from KolibriOS/kolibrios
THashView 2.6.1 :
- Optimized code. - Reduced to readable form. git-svn-id: svn://kolibrios.org@8565 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
b99f8ed178
commit
c42b0cb538
@ -15,13 +15,13 @@
|
|||||||
#define FALSE 0;
|
#define FALSE 0;
|
||||||
#define MAX_HASH_LEN 65 // Œ ªá¨¬ «ì ï ¤«¨ áâப¨
|
#define MAX_HASH_LEN 65 // Œ ªá¨¬ «ì ï ¤«¨ áâப¨
|
||||||
#define WINDOW_W 665
|
#define WINDOW_W 665
|
||||||
#define VERSION "%s - thashview 2.6"
|
#define VERSION "%s - thashview 2.6.1"
|
||||||
#define EDIT_TEXT_SIZE 0x10000000
|
#define EDIT_TEXT_SIZE 0x10000000
|
||||||
|
|
||||||
struct kolibri_system_colors sys_color_table;
|
struct kolibri_system_colors sys_color_table;
|
||||||
|
|
||||||
char hash_str_md5[MAX_HASH_LEN]= "Click the 'MD5:' button to show the md5-checksum! "; //‚뢮¤ MD5
|
char hash_str_md5[MAX_HASH_LEN]= "Click the 'MD5:' button to show the md5-checksum!"; //‚뢮¤ MD5
|
||||||
char hash_str_sha1[MAX_HASH_LEN]= "Click the 'SHA1:' button to show the sha1-checksum! "; //‚뢮¤ SHA1
|
char hash_str_sha1[MAX_HASH_LEN]= "Click the 'SHA1:' button to show the sha1-checksum!"; //‚뢮¤ SHA1
|
||||||
char hash_str_sha256[MAX_HASH_LEN]="Click the 'SHA256:' button to show the sha256-checksum!"; //‚뢮¤ SHA256
|
char hash_str_sha256[MAX_HASH_LEN]="Click the 'SHA256:' button to show the sha256-checksum!"; //‚뢮¤ SHA256
|
||||||
char edit_box_buff[MAX_HASH_LEN]; // <20>ãää¥à ¤«ï ¢¢®¤
|
char edit_box_buff[MAX_HASH_LEN]; // <20>ãää¥à ¤«ï ¢¢®¤
|
||||||
char *filename; // ˆ¬ï ®¡à ¡ âë¢ ¥¬®£® ä ©«
|
char *filename; // ˆ¬ï ®¡à ¡ âë¢ ¥¬®£® ä ©«
|
||||||
@ -60,13 +60,10 @@ void notify_show(char *text)
|
|||||||
void* safe_malloc(size_t size) // <20>¥§®¯ áë© malloc. <20>®ª §ë¢ ¥â 㢥¤®¬«¥¨¥ ®¡ ®è¨¡ª¥ ¨ § ªàë¢ ¥â ¯à®£à ¬¬ã ¥á«¨ ¯ ¬ïâì ¥ ¡ë« ¢ë¤¥«¥
|
void* safe_malloc(size_t size) // <20>¥§®¯ áë© malloc. <20>®ª §ë¢ ¥â 㢥¤®¬«¥¨¥ ®¡ ®è¨¡ª¥ ¨ § ªàë¢ ¥â ¯à®£à ¬¬ã ¥á«¨ ¯ ¬ïâì ¥ ¡ë« ¢ë¤¥«¥
|
||||||
{
|
{
|
||||||
void *p=malloc(size);
|
void *p=malloc(size);
|
||||||
if(p==NULL)
|
if(p==NULL){
|
||||||
{
|
|
||||||
notify_show("'Memory allocation error!' -E");
|
notify_show("'Memory allocation error!' -E");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}else{
|
||||||
else
|
|
||||||
{
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,12 +196,10 @@ void redraw_window() //
|
|||||||
void paste_to_edit_buffer() // ‚áâ ¢¨âì ¨§ ¡ãää¥à ®¡¬¥
|
void paste_to_edit_buffer() // ‚áâ ¢¨âì ¨§ ¡ãää¥à ®¡¬¥
|
||||||
{
|
{
|
||||||
char *temp_buff=NULL;
|
char *temp_buff=NULL;
|
||||||
if(kol_clip_num()>0)
|
if(kol_clip_num()>0){
|
||||||
{
|
|
||||||
temp_buff=kol_clip_get(kol_clip_num()-1);
|
temp_buff=kol_clip_get(kol_clip_num()-1);
|
||||||
memset(edit_box_buff,0,MAX_HASH_LEN);
|
memset(edit_box_buff,0,MAX_HASH_LEN);
|
||||||
if(DATA(int, temp_buff,0)>0 && DATA(int,temp_buff,4)==TEXT && DATA(int,temp_buff,8)==CP866)
|
if(DATA(int, temp_buff,0)>0 && DATA(int,temp_buff,4)==CLIP_TEXT && DATA(int,temp_buff,8)==CLIP_CP866){
|
||||||
{
|
|
||||||
strncpy(edit_box_buff,temp_buff+12, MAX_HASH_LEN-1);
|
strncpy(edit_box_buff,temp_buff+12, MAX_HASH_LEN-1);
|
||||||
edit_box_set_text(&hash_edit_box,edit_box_buff);
|
edit_box_set_text(&hash_edit_box,edit_box_buff);
|
||||||
notify_show("'Pasted from clipboard!' -I");
|
notify_show("'Pasted from clipboard!' -I");
|
||||||
@ -214,24 +209,27 @@ void paste_to_edit_buffer() //
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void copy_to_clipboard(char *text) // Š®¯¨à«¢ âì ¢ ¡ãää¥à ®¡¬¥
|
void copy_to_clipboard(char *text) // Š®¯¨à®¢ âì ¢ ¡ãä¥à ®¡¬¥
|
||||||
{
|
{
|
||||||
if(55!=strlen(text))
|
int text_hash_len = strlen(text)/2;
|
||||||
|
if(text_hash_len==MD5_BLOCK_SIZE ||
|
||||||
|
text_hash_len==SHA1_BLOCK_SIZE ||
|
||||||
|
text_hash_len==SHA256_BLOCK_SIZE) // …᫨ ⥪áâ ï¥âáï åíè-áâப®©
|
||||||
{
|
{
|
||||||
char *temp_buffer=safe_malloc(MAX_HASH_LEN+12);
|
char *temp_buffer=safe_malloc(MAX_HASH_LEN+12); // ‚뤥«ï¥¬ ¯ ¬ïâì ¤«ï ¢à¥¬®£® ¡ãä¥à
|
||||||
memset(temp_buffer, 0, MAX_HASH_LEN);
|
memset(temp_buffer, 0, MAX_HASH_LEN); // ‡ ã«ï¥¬ ¡ãä¥à
|
||||||
DATA(char,temp_buffer,4)=TEXT;
|
DATA(char,temp_buffer,4)=CLIP_TEXT; // “áâ ¢«¨¢ ¥¬ TEXT ¤«ï ¡ãä¥à (‘¬¥é¥¨¥ 4 ¡ ©â )
|
||||||
DATA(char,temp_buffer,8)=CP866;
|
DATA(char,temp_buffer,8)=CLIP_CP866; // “áâ ¢«¨¢ ¥¬ ª®¤¨à®¢ªã CP866(‘¬¥é¥¨¥ 8 ¡ ©â)
|
||||||
strncpy(temp_buffer+12, text, MAX_HASH_LEN-1);
|
strncpy(temp_buffer+12, text, MAX_HASH_LEN-1); // Š®¯¨à㥬 ¤ ë¥ ¨§ text ¢® ¢à¥¬¥ë© ¡ãä¥à(‘¬¥é¥¨¥ 12 ¡ ©â)
|
||||||
kol_clip_set(strlen(text)+12, temp_buffer);
|
kol_clip_set(strlen(text)+12, temp_buffer); // ‚믮«ï¥¬ á¨áâ¥¬ë© ¢ë§®¢ ¨ ¯¥à¥¬¥é ¥¬ ¤ ë¥ ¨§ ¢à¥¬¥®£® ¡ãä¥à ¢ ¡ãä¥à ®¡¬¥
|
||||||
notify_show("'Copied to clipboard!' -I");
|
notify_show("'Copied to clipboard!' -I");
|
||||||
free(temp_buffer);
|
free(temp_buffer); // Žá¢®¡®¦ ¥¬ ¢à¥¬¥ë© ¡ãä¥à.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pending_calc(char *str) // ‚뢮¤¨¬ á®®¡é¥¨¥ ® ⮬ çâ® ª®â஫ì ï á㬬¬ ¢ëç¨á«ï¥âáï.
|
void print_pending_calc(char *str) // ‚뢮¤¨¬ á®®¡é¥¨¥ ® ⮬ çâ® ª®â஫ì ï á㬬¬ ¢ëç¨á«ï¥âáï.
|
||||||
{
|
{
|
||||||
strcpy(str, "Please wait! Calculating checksum... ");
|
strcpy(str, "Please wait! Calculating checksum...");
|
||||||
redraw_window();
|
redraw_window();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,9 +243,7 @@ bool calc_and_cmp(char *hash_str_universal,int alg) //
|
|||||||
bool hash_compare() // ƒ« ¢ ï äãªæ¨ï ¤«ï áà ¢¥¨ï
|
bool hash_compare() // ƒ« ¢ ï äãªæ¨ï ¤«ï áà ¢¥¨ï
|
||||||
{
|
{
|
||||||
int alg=strlen(edit_box_buff)/2;
|
int alg=strlen(edit_box_buff)/2;
|
||||||
|
switch (alg){ // …᫨ ¢ëç¨á«¥¨ï ¥éñ ¥¡ë«®
|
||||||
switch (alg) // …᫨ ¢ëç¨á«¥¨ï ¥éñ ¥¡ë«®
|
|
||||||
{
|
|
||||||
case MD5_BLOCK_SIZE:
|
case MD5_BLOCK_SIZE:
|
||||||
if(md5_flag){
|
if(md5_flag){
|
||||||
return !strcmp(edit_box_buff,hash_str_md5);
|
return !strcmp(edit_box_buff,hash_str_md5);
|
||||||
@ -255,7 +251,6 @@ bool hash_compare() //
|
|||||||
return calc_and_cmp(hash_str_md5,alg);
|
return calc_and_cmp(hash_str_md5,alg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SHA1_BLOCK_SIZE:
|
case SHA1_BLOCK_SIZE:
|
||||||
if(sha1_flag){
|
if(sha1_flag){
|
||||||
return !strcmp(edit_box_buff,hash_str_sha1);
|
return !strcmp(edit_box_buff,hash_str_sha1);
|
||||||
@ -263,16 +258,13 @@ bool hash_compare() //
|
|||||||
return calc_and_cmp(hash_str_sha1,alg);
|
return calc_and_cmp(hash_str_sha1,alg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SHA256_BLOCK_SIZE:
|
case SHA256_BLOCK_SIZE:
|
||||||
|
|
||||||
if(sha256_flag){
|
if(sha256_flag){
|
||||||
return !strcmp(edit_box_buff,hash_str_sha256);
|
return !strcmp(edit_box_buff,hash_str_sha256);
|
||||||
}else{
|
}else{
|
||||||
return calc_and_cmp(hash_str_sha256,alg);
|
return calc_and_cmp(hash_str_sha256,alg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
break;
|
break;
|
||||||
@ -282,38 +274,30 @@ bool hash_compare() //
|
|||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
kolibri_boxlib_init(); // ‡ £à㦠¥¬ boxlib
|
kolibri_boxlib_init(); // ‡ £à㦠¥¬ boxlib
|
||||||
if(argc<2) // …᫨ à£ã¬¥â®¢ ¥â, â® § ¯ã᪠¥¬ ¤¨ «®£ ¢ë¡®à ä ©«
|
if(argc<2){ // …᫨ à£ã¬¥â®¢ ¥â, â® § ¯ã᪠¥¬ ¤¨ «®£ ¢ë¡®à ä
|
||||||
{
|
|
||||||
kolibri_dialog_init(); // § £à㦠¥¬ proc_lib(libdialog)
|
kolibri_dialog_init(); // § £à㦠¥¬ proc_lib(libdialog)
|
||||||
open_dialog* dialog = kolibri_new_open_dialog(OPEN,0, 0, 420, 320);
|
open_dialog* dialog = kolibri_new_open_dialog(OPEN,0, 0, 420, 320);
|
||||||
OpenDialog_init(dialog);
|
OpenDialog_init(dialog);
|
||||||
OpenDialog_start(dialog);
|
OpenDialog_start(dialog);
|
||||||
if(dialog->status==SUCCESS) // …᫨ ä ©« ¢ë¡à
|
if(dialog->status==SUCCESS){ // …᫨ ä ©« ¢ë¡à
|
||||||
{
|
|
||||||
global_var_init(strlen(dialog->openfile_path));
|
global_var_init(strlen(dialog->openfile_path));
|
||||||
strcpy(filename, dialog->openfile_path);
|
strcpy(filename, dialog->openfile_path);
|
||||||
}
|
}else{ // …᫨ ä ©« ¥ ¢ë¡à
|
||||||
else // …᫨ ä ©« ¥ ¢ë¡à
|
|
||||||
{
|
|
||||||
notify_show("'No file selected!' -E");
|
notify_show("'No file selected!' -E");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
free(dialog);
|
free(dialog);
|
||||||
}
|
}else{
|
||||||
else
|
|
||||||
{
|
|
||||||
global_var_init(strlen(argv[1]));
|
global_var_init(strlen(argv[1]));
|
||||||
strcpy(filename, argv[1]);
|
strcpy(filename, argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL==fopen(filename,"rb")) // …᫨ ä ©« ¥â ¨«¨ ¥ ®âªàë¢ ¥âáï
|
if(NULL==fopen(filename,"rb")){ // …᫨ ä ©« ¥â ¨«¨ ¥ ®âªàë¢ ¥âáï
|
||||||
{
|
|
||||||
notify_show("'File not found!' -E");
|
notify_show("'File not found!' -E");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(GetScreenSize()/65536<WINDOW_W)
|
if(GetScreenSize()/65536<WINDOW_W){
|
||||||
{
|
|
||||||
notify_show("'Low screen resolution! Program will not display correctrly!' -W");
|
notify_show("'Low screen resolution! Program will not display correctrly!' -W");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,8 +311,7 @@ int main(int argc, char** argv)
|
|||||||
do // –¨ª« ®¡à ¡®âª¨ ᮡë⨩
|
do // –¨ª« ®¡à ¡®âª¨ ᮡë⨩
|
||||||
{
|
{
|
||||||
gui_event = get_os_event(); // <20>®«ãç ¥¬ ᮡë⨥
|
gui_event = get_os_event(); // <20>®«ãç ¥¬ ᮡë⨥
|
||||||
switch(gui_event) // Ž¡à ¡ âë¢ ¥¬ ᮡëâ¨ï
|
switch(gui_event){ // Ž¡à ¡ âë¢ ¥¬ ᮡëâ¨ï
|
||||||
{
|
|
||||||
case KOLIBRI_EVENT_NONE:
|
case KOLIBRI_EVENT_NONE:
|
||||||
break;
|
break;
|
||||||
case KOLIBRI_EVENT_REDRAW:
|
case KOLIBRI_EVENT_REDRAW:
|
||||||
@ -343,62 +326,46 @@ int main(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
case KOLIBRI_EVENT_BUTTON: // ‘®¡ë⨥ ®¡à ¡®âª¨ ª®¯®ª
|
case KOLIBRI_EVENT_BUTTON: // ‘®¡ë⨥ ®¡à ¡®âª¨ ª®¯®ª
|
||||||
pressed_button = get_os_button(); // <20>®«ã票¥ ª®¤ ¦ ⮩ ª®¯ª¨.
|
pressed_button = get_os_button(); // <20>®«ã票¥ ª®¤ ¦ ⮩ ª®¯ª¨.
|
||||||
switch (pressed_button) // <20>஢¥àª ª ª ï ª®¯ª ¡ë« ¦ â
|
switch (pressed_button){ // <20>஢¥àª ª ª ï ª®¯ª ¡ë« ¦ â
|
||||||
{
|
|
||||||
case BTN_MD5:
|
case BTN_MD5:
|
||||||
print_pending_calc(hash_str_md5);
|
print_pending_calc(hash_str_md5);
|
||||||
sprint_hash(check_sum(MD5_BLOCK_SIZE),hash_str_md5, MD5_BLOCK_SIZE);
|
sprint_hash(check_sum(MD5_BLOCK_SIZE),hash_str_md5, MD5_BLOCK_SIZE);
|
||||||
redraw_window();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTN_SHA1:
|
case BTN_SHA1:
|
||||||
print_pending_calc(hash_str_sha1);
|
print_pending_calc(hash_str_sha1);
|
||||||
sprint_hash(check_sum(SHA1_BLOCK_SIZE),hash_str_sha1, SHA1_BLOCK_SIZE);
|
sprint_hash(check_sum(SHA1_BLOCK_SIZE),hash_str_sha1, SHA1_BLOCK_SIZE);
|
||||||
redraw_window();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTN_SHA256:
|
case BTN_SHA256:
|
||||||
print_pending_calc(hash_str_sha256);
|
print_pending_calc(hash_str_sha256);
|
||||||
sprint_hash(check_sum(SHA256_BLOCK_SIZE),hash_str_sha256, SHA256_BLOCK_SIZE);
|
sprint_hash(check_sum(SHA256_BLOCK_SIZE),hash_str_sha256, SHA256_BLOCK_SIZE);
|
||||||
redraw_window();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTN_COPY_MD5:
|
case BTN_COPY_MD5:
|
||||||
copy_to_clipboard(hash_str_md5);
|
copy_to_clipboard(hash_str_md5);
|
||||||
redraw_window();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTN_COPY_SHA1:
|
case BTN_COPY_SHA1:
|
||||||
copy_to_clipboard(hash_str_sha1);
|
copy_to_clipboard(hash_str_sha1);
|
||||||
redraw_window();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTN_COPY_SHA256:
|
case BTN_COPY_SHA256:
|
||||||
copy_to_clipboard(hash_str_sha256);
|
copy_to_clipboard(hash_str_sha256);
|
||||||
redraw_window();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTN_PASTE:
|
case BTN_PASTE:
|
||||||
paste_to_edit_buffer();
|
paste_to_edit_buffer();
|
||||||
redraw_window();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTN_CMP:
|
case BTN_CMP:
|
||||||
if(hash_compare())
|
if(hash_compare()){
|
||||||
{
|
|
||||||
notify_show("'The checksum matches :)' -OK");
|
notify_show("'The checksum matches :)' -OK");
|
||||||
hash_edit_box.text_color = GREEN; // “áâ ¢«¨¢ ¥¬ ⥪áâ ¢¢®¤ §¥«ñë¬ ¥á«¨ ª®â஫ì ï á㬬 ᮢ¯ ¤ ¥â
|
hash_edit_box.text_color = GREEN; // “áâ ¢«¨¢ ¥¬ ⥪áâ ¢¢®¤ §¥«ñë¬ ¥á«¨ ª®â஫ì ï á㬬 ᮢ¯ ¤ ¥â
|
||||||
}else{
|
}else{
|
||||||
notify_show("'The checksum does not match! :(' -W");
|
notify_show("'The checksum does not match! :(' -W");
|
||||||
hash_edit_box.text_color = RED; // “áâ ¢«¨¢ ¥¬ ⥪áâ ¢¢®¤ ªà áë¬ ¥á«¨ ª®â஫ì ï áã¬¬ë ¥ ᮢ¯ ¤ ¥â
|
hash_edit_box.text_color = RED; // “áâ ¢«¨¢ ¥¬ ⥪áâ ¢¢®¤ ªà áë¬ ¥á«¨ ª®â஫ì ï áã¬¬ë ¥ ᮢ¯ ¤ ¥â
|
||||||
}
|
}
|
||||||
redraw_window();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTN_QUIT:
|
case BTN_QUIT:
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
redraw_window();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}while(1);
|
}while(1);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user