TinyHashView 2.6: added editbox from boxlib library.

git-svn-id: svn://kolibrios.org@8466 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
superturbocat2001 2020-12-21 18:42:34 +00:00
parent 4d192ca472
commit b7804a951e
4 changed files with 45 additions and 85 deletions

View File

@ -1,2 +1,2 @@
#SHS
/kolibrios/develop/tcc/tcc thashview.c -o thashview -lck -lcryptal -ldialog
/kolibrios/develop/tcc/tcc thashview.c -o thashview -lck -lcryptal -ldialog -lbox

View File

@ -7,7 +7,7 @@ KPACK=kpack
SRC=thashview.c
CFLAGS=-I $(KTCC_DIR)/libc/include
LIBS = -lck -lcryptal -ldialog
LIBS = -lck -lcryptal -ldialog -lbox
all:
$(KTCC) $(CFLAGS) $(SRC) $(LIBS) -o $(NAME)

View File

@ -1,10 +1,10 @@
if tup.getconfig("NO_TCC") ~= "" then return end
TCC="kos32-tcc "
TCC="kos32-tcc"
CFLAGS = "-I../../develop/ktcc/trunk/libc/include"
LDFLAGS = "-nostdlib ../../develop/ktcc/trunk/bin/lib/start.o -L../../develop/ktcc/trunk/bin/lib"
LIBS = "-lck -lcryptal -ldialog"
LIBS = "-lck -lcryptal -ldialog -lbox"
COMMAND=string.format("%s %s %s %s %s ", TCC, CFLAGS, "%f -o %o", LDFLAGS, LIBS)
tup.rule("thashview.c", COMMAND .. tup.getconfig("KPACK_CMD"), "thashview")

View File

@ -5,21 +5,21 @@
#include <stdlib.h>
#include <kos32sys1.h>
#include <string.h>
#include <stdarg.h>
#include <cryptal/md5.h>
#include <cryptal/sha1.h>
#include <cryptal/sha256.h>
#include <clayer/dialog.h>
#include <clayer/boxlib.h>
#define TRUE 1;
#define FALSE 0;
#define MAX_HASH_LEN 65 // Œ ªá¨¬ «ì­ ï ¤«¨­  áâப¨
#define WINDOW_W 665
#define VERSION "%s - thashview 2.5"
#define VERSION "%s - thashview 2.6"
#define EDIT_TEXT_SIZE 0x10000000
struct kolibri_system_colors sys_color_table;
char hex[]={"abcdefABCDEF1234567890"}; //„«ï ¯à®¢¥àª¨ ¢¢®¤¨¬ëå ᨬ¢®«®¢
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_sha256[MAX_HASH_LEN]="Click the 'SHA256:' button to show the sha256-checksum!"; //‚뢮¤ SHA256
@ -29,22 +29,15 @@ char *title; //
enum MYCOLORS // –¢¥â 
{
GREEN = 0x00067D06,
RED = 0x00FF0000,
BLACK = 0x00000000,
WHITE = 0xFFFFFFFF,
GREY = 0x00DDD7CF
GREEN = 0x067D06 | EDIT_TEXT_SIZE,
RED = 0xFF0000 | EDIT_TEXT_SIZE,
BLACK = 0x000000 | EDIT_TEXT_SIZE,
WHITE = 0xFFFFFF,
GREY = 0x919191
};
unsigned int str_pos=0; // <20>®§¨æ¨ï ªãàá®à  ¯à¨ ¯¥ç â¨ ¢ áâப¥ ¢¢®¤ 
edit_box hash_edit_box={WINDOW_W-140,10,121,WHITE,0,0,GREY,EDIT_TEXT_SIZE, MAX_HASH_LEN-1, edit_box_buff,NULL,ed_focus}; // ‘®§¤ ñ¬ áâàãªâãàã edit_box
int md5_flag=0, sha1_flag=0, sha256_flag=0; // ”« £¨ ¯®ª §ë¢ î騥 ¡ë«  «¨ 㦥 à ááç¨â ­  ª®â஫쭠ï á㬬  ¢ ä㭪樨 check_sum()
int edit_box_text_color=BLACK; // ˆ§­ ç «ì­ë© 梥â ⥪áâ  ¢ áâப¥ ¢¢®¤ 
enum MYKEYS // Š®¤ë ª« ¢¨è
{
CTRL_V=22,
BACKSPACE=8
};
enum BUTTONS // Š­®¯ª¨ ¢ ¨­âà¥ä¥©á¥
{
@ -174,13 +167,11 @@ void redraw_window() //
begin_draw(); //<2F> ç¨­ ¥¬ à¨á®¢ ­¨¥ ¨­â¥àä¥©á  )
sys_create_window(win_pos.x, win_pos.y, WINDOW_W, 150, title, sys_color_table.work_area, 0x14); // ‘®§¤ ñ¬ ®ª­®.
draw_bar(10, 121, 525,20, WHITE); // ‘®§¤ ñ¬ ¯àאַ㣮«ì­¨ª ¤«ï ¯®«ï ¢¢®¤ 
draw_text_sys(edit_box_buff,15, 125, 0, 0x90000000| edit_box_text_color); // ‚뢮¤¨¬ ⥪áâ ¨§ ¡ãää¥à  ¢¢®¤ 
draw_text_sys("|",10+(8*str_pos),125,0,0x90000000 | BLACK);
edit_box_draw(&hash_edit_box); // <20>¨á㥬 edit_box
define_button((10 << 16) + 60, (30 << 16) + 20, BTN_MD5, GREEN); // Ž¯à¥¤¥«ï¥¬ ª­®¯ªã md5
define_button((10 << 16) + 60, (60 << 16) + 20, BTN_SHA1, GREEN);// Ž¯à¥¤¥«ï¥¬ ª­®¯ªã sha1
define_button((10 << 16) + 60, (90 << 16) + 20, BTN_SHA256, GREEN);// Ž¯à¥¤¥«ï¥¬ ª­®¯ªã sha256
define_button(X_W(10,60), Y_H(30,20), BTN_MD5, GREEN); // Ž¯à¥¤¥«ï¥¬ ª­®¯ªã md5
define_button(X_W(10,60), Y_H(60,20), BTN_SHA1, GREEN);// Ž¯à¥¤¥«ï¥¬ ª­®¯ªã sha1
define_button(X_W(10,60), Y_H(90,20), BTN_SHA256, GREEN);// Ž¯à¥¤¥«ï¥¬ ª­®¯ªã sha256
draw_text_sys("MD5:", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); // <20>¨é¥¬ ⥪áâ ­  ª­®¯ª å
draw_text_sys("SHA1:", 15, 64, 0, 0x90000000 | sys_color_table.work_button_text);
@ -190,23 +181,21 @@ void redraw_window() //
draw_text_sys(hash_str_sha1, 80, 64, 0, 0x90000000 | sys_color_table.work_text);
draw_text_sys(hash_str_sha256, 80, 94, 0, 0x90000000| sys_color_table.work_text);
define_button((610 << 16) + 42, (30 << 16) + 20, BTN_COPY_MD5, sys_color_table.work_button); // Ž¯à¥¤¥«ï¥¬ ª­®¯ª¨ ¤«ï ª®¯¨à®¢ ­¨ï
define_button((610<< 16) + 42, (60 << 16) + 20, BTN_COPY_SHA1, sys_color_table.work_button);
define_button((610<< 16) + 42, (90 << 16) + 20, BTN_COPY_SHA256, sys_color_table.work_button);
define_button(X_W(610,42), Y_H(30, 20), BTN_COPY_MD5, sys_color_table.work_button); // Ž¯à¥¤¥«ï¥¬ ª­®¯ª¨ ¤«ï ª®¯¨à®¢ ­¨ï
define_button(X_W(610,42), Y_H(60, 20), BTN_COPY_SHA1, sys_color_table.work_button);
define_button(X_W(610,42), Y_H(90, 20), BTN_COPY_SHA256, sys_color_table.work_button);
draw_text_sys("Copy", 615, 34, 0, 0x90000000 | sys_color_table.work_button_text); // <20>¨è¥¬ copy ­  ¢á¥å ª­®¯ª å ¤«ï ª®¯¨à®¢ ­¨ï
draw_text_sys("Copy", 615, 64, 0, 0x90000000 | sys_color_table.work_button_text);
draw_text_sys("Copy", 615, 94, 0, 0x90000000 | sys_color_table.work_button_text);
define_button((592<< 16) + 60, (120 << 16) + 20, BTN_CMP, GREEN); // Ž¯à¥¤¥«ï¥¬ ª­®¯ªã ¤«ï áà ¢­¥­¨ï ª®­â®«ì­ëå á㬬
define_button(X_W(592,60), Y_H(120,20), BTN_CMP, GREEN); // Ž¯à¥¤¥«ï¥¬ ª­®¯ªã ¤«ï áà ¢­¥­¨ï ª®­â®«ì­ëå á㬬
draw_text_sys("Compare", 595, 124 , 0,0x90000000 | sys_color_table.work_button_text); // <20>¨è¥¬ â¥ªá ­  ª­®¯ª¥.
define_button((540 << 16) + 45, (120 << 16) + 20, BTN_PASTE, sys_color_table.work_button); //Š­®¯ª  ¤«ï ¢áâ ¢ª¨ (­¥à ¡®â ¥â)
define_button(X_W(540, 45), Y_H(120,20), BTN_PASTE, sys_color_table.work_button); //Š­®¯ª  ¤«ï ¢áâ ¢ª¨ (­¥à ¡®â ¥â)
draw_text_sys("Paste", 543, 124 , 0,0x90000000 | sys_color_table.work_button_text); // ’¥ªáâ paste ­  ª­®¯ª¥
end_draw();
}
void paste_to_edit_buffer() // ‚áâ ¢¨âì ¨§ ¡ãää¥à  ®¡¬¥­ 
{
char *temp_buff=NULL;
@ -217,15 +206,14 @@ void paste_to_edit_buffer() //
if(DATA(int, temp_buff,0)>0 && DATA(int,temp_buff,4)==TEXT && DATA(int,temp_buff,8)==CP866)
{
strncpy(edit_box_buff,temp_buff+12, MAX_HASH_LEN-1);
str_pos=strlen(edit_box_buff);
edit_box_set_text(&hash_edit_box,edit_box_buff);
notify_show("'Pasted from clipboard!' -I");
edit_box_text_color=BLACK;
hash_edit_box.text_color = BLACK;
user_free(temp_buff);
}
}
}
void copy_to_clipboard(char *text) // Š®¯¨à«¢ âì ¢ ¡ãää¥à ®¡¬¥­ 
{
if(55!=strlen(text))
@ -261,35 +249,26 @@ bool hash_compare() //
switch (alg) // …᫨ ¢ëç¨á«¥­¨ï ¥éñ ­¥¡ë«®
{
case MD5_BLOCK_SIZE:
if(md5_flag)
{
if(md5_flag){
return !strcmp(edit_box_buff,hash_str_md5);
}
else
{
}else{
return calc_and_cmp(hash_str_md5,alg);
}
break;
case SHA1_BLOCK_SIZE:
if(sha1_flag)
{
if(sha1_flag){
return !strcmp(edit_box_buff,hash_str_sha1);
}
else
{
}else{
return calc_and_cmp(hash_str_sha1,alg);
}
break;
case SHA256_BLOCK_SIZE:
if(sha256_flag)
{
if(sha256_flag){
return !strcmp(edit_box_buff,hash_str_sha256);
}
else
{
}else{
return calc_and_cmp(hash_str_sha256,alg);
}
break;
@ -300,34 +279,12 @@ bool hash_compare() //
}
}
void edit_box(oskey_t key) //”ã­ªæ¨ï ॠ«¨§ãîé ï áâப㠢¢®¤ 
{
edit_box_text_color=BLACK;
if(key.code==CTRL_V) // …᫨ ­ ¦ â® Ctrl+V â® ¢áâ ¢¨âì ¨§ ¡ãä¥à  ®¡¬¥­ 
{
paste_to_edit_buffer();
}
if(key.code==BACKSPACE && str_pos>0) // …᫨ backspace ⮠㤠«¨âì ¯®á«¥¤­¨© ᨬ¢®«
{
str_pos--;
edit_box_buff[str_pos]='\0';
}
else if(str_pos<MAX_HASH_LEN-1) // Ž£à ­¨ç¥­¨¥ ¤«¨­ë ¢¢®¤ 
{
if(strchr(hex,key.code)!=NULL)
{
edit_box_buff[str_pos]=key.code;
str_pos++;
}
}
}
int main(int argc, char** argv)
{
kolibri_boxlib_init(); // ‡ £à㦠¥¬ boxlib
if(argc<2) // …᫨  à£ã¬¥­â®¢ ­¥â, â® § ¯ã᪠¥¬ ¤¨ «®£ ¢ë¡®à  ä ©« 
{
kolibri_dialog_init(); // ˆ­¨æ¨ «¨§ æ¨ï ¡¨¡«¨®â¥ª¨
kolibri_dialog_init(); // § £à㦠¥¬ proc_lib(libdialog)
open_dialog* dialog = kolibri_new_open_dialog(OPEN,0, 0, 420, 320);
OpenDialog_init(dialog);
OpenDialog_start(dialog);
@ -364,6 +321,8 @@ int main(int argc, char** argv)
uint32_t pressed_button = 0; // Š®¤ ­ ¦ â®© ª­®¯ª¨ ¢ ®ª­¥
get_system_colors(&sys_color_table);
hash_edit_box.shift_color=sys_color_table.work_button;
set_event_mask(0xC0000027);// “áâ ­ ¢«¨¢ ¥¬ ¬ áªã ᮡë⨩
do // –¨ª« ®¡à ¡®âª¨ ᮡë⨩
{
@ -375,9 +334,12 @@ int main(int argc, char** argv)
case KOLIBRI_EVENT_REDRAW:
redraw_window();
break;
case KOLIBRI_EVENT_MOUSE:
edit_box_mouse(&hash_edit_box);
break;
case KOLIBRI_EVENT_KEY:
edit_box(get_key()); // <20>®«ãç ¥¬ ­ ¦ âãî ª« ¢¨èã ¨ § ¤¥©áâ¢ã¥¬ áâப㠢¢®¤ 
redraw_window();
hash_edit_box.text_color = BLACK;
edit_box_key(&hash_edit_box,get_key().val);
break;
case KOLIBRI_EVENT_BUTTON: // ‘®¡ë⨥ ®¡à ¡®âª¨ ª­®¯®ª
pressed_button = get_os_button(); // <20>®«ã祭¨¥ ª®¤  ­ ¦ â®© ª­®¯ª¨.
@ -402,18 +364,18 @@ int main(int argc, char** argv)
break;
case BTN_COPY_MD5:
redraw_window();
copy_to_clipboard(hash_str_md5);
redraw_window();
break;
case BTN_COPY_SHA1:
redraw_window();
copy_to_clipboard(hash_str_sha1);
redraw_window();
break;
case BTN_COPY_SHA256:
redraw_window();
copy_to_clipboard(hash_str_sha256);
redraw_window();
break;
case BTN_PASTE:
@ -425,12 +387,10 @@ int main(int argc, char** argv)
if(hash_compare())
{
notify_show("'The checksum matches :)' -OK");
edit_box_text_color=GREEN; // “áâ ­ ¢«¨¢ ¥¬ ⥪áâ ¢¢®¤  §¥«ñ­ë¬ ¥á«¨ ª®­â஫쭠ï á㬬  ᮢ¯ ¤ ¥â
}
else
{
hash_edit_box.text_color = GREEN; // “áâ ­ ¢«¨¢ ¥¬ ⥪áâ ¢¢®¤  §¥«ñ­ë¬ ¥á«¨ ª®­â஫쭠ï á㬬  ᮢ¯ ¤ ¥â
}else{
notify_show("'The checksum does not match! :(' -W");
edit_box_text_color=RED; // “áâ ­ ¢«¨¢ ¥¬ ⥪áâ ¢¢®¤  ªà á­ë¬ ¥á«¨ ª®­â஫쭠ï áã¬¬ë ­¥ ᮢ¯ ¤ ¥â
hash_edit_box.text_color = RED; // “áâ ­ ¢«¨¢ ¥¬ ⥪áâ ¢¢®¤  ªà á­ë¬ ¥á«¨ ª®­â஫쭠ï áã¬¬ë ­¥ ᮢ¯ ¤ ¥â
}
redraw_window();
break;