[perl]hotkey
来源:互联网 发布:淘宝营销活动有哪些 编辑:程序博客网 时间:2024/06/07 04:01
use strict;
use warnings;
use File::Copy ;
use Encode qw#encode decode# ;
use Spreadsheet::WriteExcel;
use File::Find;
use Win32::GUI();
use Win32;
my ($DOS) = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($DOS);
my ($filedir,$fileextions,$outdir) = @ARGV;
my @fileextions;
my $rootdir = Win32::GetCwd();
chdir($rootdir);
my $MyIcon = Win32::GUI::Icon->new("logo.ico");
my $MyClass = new Win32::GUI::Class(-name => "changed_icon",
-icon => $MyIcon,);
my $W1 = Win32::GUI::Window->new(
-name => "W1",
-title => "Hotkey tool v1.1",
-maximizebox => 0,
-resizable => 0,
-pos => [30, 30],
-size => [500, 170],
-class => $MyClass,
);
my $inputfile_textfiled =
$W1->AddTextfield(
-name => 'Textfield1',
-text => '',
-prompt => ["PII folder path:", 90],
-pos => [10, 20],
-size => [310, 20],
-align => 'left',
);
my $b1 =$W1->AddButton(-name => "Button1", -text => "Browser..", -pos => [420, 20],-size => [60, 20],);
my $inputfile_textfiled2 =
$W1->AddTextfield(
-name => 'Textfield2',
-text => '',
-prompt => ["Output folder path:", 90],
-pos => [10, 50],
-size => [310, 20],
-align => 'left',
);
my $b2 =$W1->AddButton(-name => "Button2", -text => "Browser..", -pos => [420, 50],-size => [60, 20],);
my $inputfile_textfiled3 =
$W1->AddTextfield(
-name => 'Textfield3',
-text => '',
-prompt => ["File extension:", 90],
-pos => [10, 80],
-size => [310, 20],
-align => 'left',
);
my $b3 =$W1->AddButton(
-name => "Button3",
-text => "Start",
-pos => [180, 110],
-size => [100, 20]
);
$W1->Center();
$W1->Show();
Win32::GUI::Dialog();
exit(0);
sub Button1_Click{
$filedir =
Win32::GUI::BrowseForFolder(
-title => "Select PII folder path..",
-directory => $rootdir,
-newui => 1,
-nonewfolder => 1,
);
$inputfile_textfiled->{'-text'} = $filedir;
return 1;
}
sub Button2_Click{
my $outfir =
Win32::GUI::BrowseForFolder(
-title => "Select output folder path..",
-directory => $rootdir,
-newui => 1,
);
$inputfile_textfiled2->{'-text'} = $outfir;
return 1;
}
sub Button3_Click{
$filedir = $inputfile_textfiled->{'-text'};
if (($filedir cmp "")==0){
Win32::MsgBox('Please input PII folder path!', MB_ICONINFORMATION, '');
return 1;
};
$outdir = $inputfile_textfiled2->{'-text'};
if(($outdir cmp "")==0){
Win32::MsgBox('Please input output folder path!', MB_ICONINFORMATION, '');
return 1;
};
$fileextions = $inputfile_textfiled3->{'-text'};
if (($fileextions cmp "")==0){
Win32::MsgBox('Plesae input file extension, multiple file extensions separated by semicolons.', MB_ICONINFORMATION, '');
return 1;
};
@fileextions = split(/\;/,$fileextions);
$b3->{'-text'}="Analysising..";
if (!(-d $outdir)){
mkdir $outdir;
}
hotkey($filedir);
Win32::MsgBox('Complete!', MB_ICONINFORMATION, '');
$b3->{'-text'}='Start';
return 1;
}
sub W1_Terminate{
return -1;
}
sub hotkey{
my ($filedir) = @_;
find(\&process, $filedir);
}
sub process {
my $file = $File::Find::name;
if (-f $file) {
foreach my $fileextion ( @fileextions ){
if ( $file =~ /\Q$fileextion\E$/ ){
if($file=~/(.*\/)(.*)/){
my $dir=$1;
opendir(DH, "$dir") or die "Can't open: $!\n" ;
my $name=$2;
processfile($name);
closedir(DH);
}
}
}
}
}
sub processfile {
my ($file) = @_;
my $description1;
my $description2;
my $resultfile;
my $encoding ="utf8";
my $button;
my $button2;
my $lineIDK;
my $lineIDS;
my $hotkey;
my $hotkeyinIDS;
my $hotkeystring;
my @linelists=();
my @newlines=();
my $des1;
my $des2;
my $row = 2;
$resultfile=$file;
$resultfile=$outdir."\\".$resultfile."\.xls";
open( FILEREAD , "<:raw", "$file") or die "Cannot open $file file!\n\n";
my $file_content = do { local $/; <FILEREAD> } ;
close( FILEREAD ) ;
my $text = decode( $encoding , $file_content ) ;
my @lines = split( /\r\n/ , $text ) ;
$des1=detectcs($file);
$des2=detectrupl($file);
foreach my $line ( @lines ) {
$line=~s/\s+//g;
if($line =~/^\{\"IDK_(.*)\"\,KeyEvent.VK_(.*)\}\,/i){
$lineIDK=$line;
$hotkey=$2;
if($hotkey=~/SLASH/){
$hotkey="\/";
}
if($hotkey=~/PERIOD/){
$hotkey="\.";
}
if($hotkey=~/GREATER/){
$hotkey="\>";
}
$button="IDS_$1";
$button=~s/_KEY//;
$button2="$button"."_TEXT";
foreach my $line ( @lines ) {
$line=~s/\s+//g;
if (($line =~/\{\"\Q$button\E\"\,\"(.*)\"/i)||($line =~/\{\"\Q$button2\E"\,\"(.*)\"/i)){
$lineIDS=$line;
$hotkeystring=$1;
if((($des1 cmp "Double byte")==0)&&(($des2 cmp "Not Russian or Polish")==0)){
$description1="Double byte";
if($hotkeystring=~/\((.*)\)/i){
$hotkeyinIDS=$1;
if(($hotkeyinIDS=~/\Q$hotkey\E/i)&&(length($hotkeyinIDS)==1)){
$description2="pass!";
}else{
$description2="inconsistent hotkey !";
}
}else{
$description2="missing hotkey!";
}
}elsif(($des1 cmp "Single byte")==0){
$description1="Single byte";
if($hotkeystring=~/\Q$hotkey\E/i){
$description2="pass!";
}else{
$description2="inconsistent hotkey!";
}
}elsif(($des2 cmp "Russian or Polish")==0){
$description1="Russian or Polish";
if($hotkeystring=~/\Q$hotkey\E/i){
$description2="pass!";
}else{
$description2="inconsistent hotkey!";
}
}
my @linelists=("$lineIDK","$lineIDS","$hotkey","$hotkeystring","$description1","$description2");
if(($description2 cmp "pass!")==0){
}else{
my $newline;
$newline=join("\;\;\;\;\;\;",@linelists);
# print "$newline\n";
push( @newlines , "$newline");
}
}
}
}
}
if ( scalar(@newlines)>0){
my $workbook = Spreadsheet::WriteExcel -> new("$resultfile");
my $worksheet = $workbook -> add_worksheet('sheet1');
$worksheet->freeze_panes(1, 0);
$worksheet->set_column(0,1,70);
$worksheet->set_column(2,2,10);
$worksheet->set_column(3,3,30);
$worksheet->set_column(4,5,20);
my $headformat = $workbook->add_format();
$headformat->set_bold();
$headformat->set_size('13');
$headformat->set_align('center');
my $normcell = $workbook->add_format();
$normcell->set_size('11');
$normcell->set_align('left');
my @firstline=("lineIDK","lineIDS","hotkey","hotkeystring","CS","description");
$worksheet->write("A1", \@firstline,$headformat);
foreach my $newline ( @newlines ) {
my @fields = split(/\;\;\;\;\;\;/,$newline);
$worksheet->write("A$row", \@fields,$normcell);
$row++;
}
$workbook.close();
}
}
sub detectcs {
my ($file) = @_;
my $encoding ="utf8";
open( FILEREAD , "<:raw", "$file") or die "Cannot open $file file!\n\n";
my $file_content = do { local $/; <FILEREAD> } ;
close( FILEREAD ) ;
my $text = decode( $encoding , $file_content ) ;
my @lines = split( /\r\n/ , $text ) ;
my $des;
foreach my $line ( @lines ) {
$line=~s/\s+//g;
if ($line =~/\{\"IDS(.*)\"\,\"(.*)\"/i){
if($2=~/[^\x00-\xff]/){
$des="Double byte";
last;
}else{
$des="Single byte";
}
}
}
return $des;
}
sub detectrupl {
my ($file) = @_;
my $encoding ="utf8";
open( FILEREAD , "<:raw", "$file") or die "Cannot open $file file!\n\n";
my $file_content = do { local $/; <FILEREAD> } ;
close( FILEREAD ) ;
my $eyu="АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщъЫыьЭэЮюЯяĄąĆćĘꣳŃńŚśŹźŻż";
$eyu=decode( $encoding , $eyu );
my $text = decode( $encoding , $file_content ) ;
my @lines = split( /\r\n/ , $text );
my $des;
foreach my $line ( @lines ) {
$line=~s/\s+//g;
if ($line =~/\{\"IDS(.*)\"\,\"(.*)\"/i){
if($2=~/[\Q$eyu\E]/){
$des="Russian or Polish";
last;
}else{
$des="Not Russian or Polish";
}
}
}
return $des;
}
use warnings;
use File::Copy ;
use Encode qw#encode decode# ;
use Spreadsheet::WriteExcel;
use File::Find;
use Win32::GUI();
use Win32;
my ($DOS) = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($DOS);
my ($filedir,$fileextions,$outdir) = @ARGV;
my @fileextions;
my $rootdir = Win32::GetCwd();
chdir($rootdir);
my $MyIcon = Win32::GUI::Icon->new("logo.ico");
my $MyClass = new Win32::GUI::Class(-name => "changed_icon",
-icon => $MyIcon,);
my $W1 = Win32::GUI::Window->new(
-name => "W1",
-title => "Hotkey tool v1.1",
-maximizebox => 0,
-resizable => 0,
-pos => [30, 30],
-size => [500, 170],
-class => $MyClass,
);
my $inputfile_textfiled =
$W1->AddTextfield(
-name => 'Textfield1',
-text => '',
-prompt => ["PII folder path:", 90],
-pos => [10, 20],
-size => [310, 20],
-align => 'left',
);
my $b1 =$W1->AddButton(-name => "Button1", -text => "Browser..", -pos => [420, 20],-size => [60, 20],);
my $inputfile_textfiled2 =
$W1->AddTextfield(
-name => 'Textfield2',
-text => '',
-prompt => ["Output folder path:", 90],
-pos => [10, 50],
-size => [310, 20],
-align => 'left',
);
my $b2 =$W1->AddButton(-name => "Button2", -text => "Browser..", -pos => [420, 50],-size => [60, 20],);
my $inputfile_textfiled3 =
$W1->AddTextfield(
-name => 'Textfield3',
-text => '',
-prompt => ["File extension:", 90],
-pos => [10, 80],
-size => [310, 20],
-align => 'left',
);
my $b3 =$W1->AddButton(
-name => "Button3",
-text => "Start",
-pos => [180, 110],
-size => [100, 20]
);
$W1->Center();
$W1->Show();
Win32::GUI::Dialog();
exit(0);
sub Button1_Click{
$filedir =
Win32::GUI::BrowseForFolder(
-title => "Select PII folder path..",
-directory => $rootdir,
-newui => 1,
-nonewfolder => 1,
);
$inputfile_textfiled->{'-text'} = $filedir;
return 1;
}
sub Button2_Click{
my $outfir =
Win32::GUI::BrowseForFolder(
-title => "Select output folder path..",
-directory => $rootdir,
-newui => 1,
);
$inputfile_textfiled2->{'-text'} = $outfir;
return 1;
}
sub Button3_Click{
$filedir = $inputfile_textfiled->{'-text'};
if (($filedir cmp "")==0){
Win32::MsgBox('Please input PII folder path!', MB_ICONINFORMATION, '');
return 1;
};
$outdir = $inputfile_textfiled2->{'-text'};
if(($outdir cmp "")==0){
Win32::MsgBox('Please input output folder path!', MB_ICONINFORMATION, '');
return 1;
};
$fileextions = $inputfile_textfiled3->{'-text'};
if (($fileextions cmp "")==0){
Win32::MsgBox('Plesae input file extension, multiple file extensions separated by semicolons.', MB_ICONINFORMATION, '');
return 1;
};
@fileextions = split(/\;/,$fileextions);
$b3->{'-text'}="Analysising..";
if (!(-d $outdir)){
mkdir $outdir;
}
hotkey($filedir);
Win32::MsgBox('Complete!', MB_ICONINFORMATION, '');
$b3->{'-text'}='Start';
return 1;
}
sub W1_Terminate{
return -1;
}
sub hotkey{
my ($filedir) = @_;
find(\&process, $filedir);
}
sub process {
my $file = $File::Find::name;
if (-f $file) {
foreach my $fileextion ( @fileextions ){
if ( $file =~ /\Q$fileextion\E$/ ){
if($file=~/(.*\/)(.*)/){
my $dir=$1;
opendir(DH, "$dir") or die "Can't open: $!\n" ;
my $name=$2;
processfile($name);
closedir(DH);
}
}
}
}
}
sub processfile {
my ($file) = @_;
my $description1;
my $description2;
my $resultfile;
my $encoding ="utf8";
my $button;
my $button2;
my $lineIDK;
my $lineIDS;
my $hotkey;
my $hotkeyinIDS;
my $hotkeystring;
my @linelists=();
my @newlines=();
my $des1;
my $des2;
my $row = 2;
$resultfile=$file;
$resultfile=$outdir."\\".$resultfile."\.xls";
open( FILEREAD , "<:raw", "$file") or die "Cannot open $file file!\n\n";
my $file_content = do { local $/; <FILEREAD> } ;
close( FILEREAD ) ;
my $text = decode( $encoding , $file_content ) ;
my @lines = split( /\r\n/ , $text ) ;
$des1=detectcs($file);
$des2=detectrupl($file);
foreach my $line ( @lines ) {
$line=~s/\s+//g;
if($line =~/^\{\"IDK_(.*)\"\,KeyEvent.VK_(.*)\}\,/i){
$lineIDK=$line;
$hotkey=$2;
if($hotkey=~/SLASH/){
$hotkey="\/";
}
if($hotkey=~/PERIOD/){
$hotkey="\.";
}
if($hotkey=~/GREATER/){
$hotkey="\>";
}
$button="IDS_$1";
$button=~s/_KEY//;
$button2="$button"."_TEXT";
foreach my $line ( @lines ) {
$line=~s/\s+//g;
if (($line =~/\{\"\Q$button\E\"\,\"(.*)\"/i)||($line =~/\{\"\Q$button2\E"\,\"(.*)\"/i)){
$lineIDS=$line;
$hotkeystring=$1;
if((($des1 cmp "Double byte")==0)&&(($des2 cmp "Not Russian or Polish")==0)){
$description1="Double byte";
if($hotkeystring=~/\((.*)\)/i){
$hotkeyinIDS=$1;
if(($hotkeyinIDS=~/\Q$hotkey\E/i)&&(length($hotkeyinIDS)==1)){
$description2="pass!";
}else{
$description2="inconsistent hotkey !";
}
}else{
$description2="missing hotkey!";
}
}elsif(($des1 cmp "Single byte")==0){
$description1="Single byte";
if($hotkeystring=~/\Q$hotkey\E/i){
$description2="pass!";
}else{
$description2="inconsistent hotkey!";
}
}elsif(($des2 cmp "Russian or Polish")==0){
$description1="Russian or Polish";
if($hotkeystring=~/\Q$hotkey\E/i){
$description2="pass!";
}else{
$description2="inconsistent hotkey!";
}
}
my @linelists=("$lineIDK","$lineIDS","$hotkey","$hotkeystring","$description1","$description2");
if(($description2 cmp "pass!")==0){
}else{
my $newline;
$newline=join("\;\;\;\;\;\;",@linelists);
# print "$newline\n";
push( @newlines , "$newline");
}
}
}
}
}
if ( scalar(@newlines)>0){
my $workbook = Spreadsheet::WriteExcel -> new("$resultfile");
my $worksheet = $workbook -> add_worksheet('sheet1');
$worksheet->freeze_panes(1, 0);
$worksheet->set_column(0,1,70);
$worksheet->set_column(2,2,10);
$worksheet->set_column(3,3,30);
$worksheet->set_column(4,5,20);
my $headformat = $workbook->add_format();
$headformat->set_bold();
$headformat->set_size('13');
$headformat->set_align('center');
my $normcell = $workbook->add_format();
$normcell->set_size('11');
$normcell->set_align('left');
my @firstline=("lineIDK","lineIDS","hotkey","hotkeystring","CS","description");
$worksheet->write("A1", \@firstline,$headformat);
foreach my $newline ( @newlines ) {
my @fields = split(/\;\;\;\;\;\;/,$newline);
$worksheet->write("A$row", \@fields,$normcell);
$row++;
}
$workbook.close();
}
}
sub detectcs {
my ($file) = @_;
my $encoding ="utf8";
open( FILEREAD , "<:raw", "$file") or die "Cannot open $file file!\n\n";
my $file_content = do { local $/; <FILEREAD> } ;
close( FILEREAD ) ;
my $text = decode( $encoding , $file_content ) ;
my @lines = split( /\r\n/ , $text ) ;
my $des;
foreach my $line ( @lines ) {
$line=~s/\s+//g;
if ($line =~/\{\"IDS(.*)\"\,\"(.*)\"/i){
if($2=~/[^\x00-\xff]/){
$des="Double byte";
last;
}else{
$des="Single byte";
}
}
}
return $des;
}
sub detectrupl {
my ($file) = @_;
my $encoding ="utf8";
open( FILEREAD , "<:raw", "$file") or die "Cannot open $file file!\n\n";
my $file_content = do { local $/; <FILEREAD> } ;
close( FILEREAD ) ;
my $eyu="АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщъЫыьЭэЮюЯяĄąĆćĘꣳŃńŚśŹźŻż";
$eyu=decode( $encoding , $eyu );
my $text = decode( $encoding , $file_content ) ;
my @lines = split( /\r\n/ , $text );
my $des;
foreach my $line ( @lines ) {
$line=~s/\s+//g;
if ($line =~/\{\"IDS(.*)\"\,\"(.*)\"/i){
if($2=~/[\Q$eyu\E]/){
$des="Russian or Polish";
last;
}else{
$des="Not Russian or Polish";
}
}
}
return $des;
}
0 0
- [perl]hotkey
- hotkey
- HotKey
- hotkey
- HotKey
- Cvim hotKey
- hotkey.ahk
- VC++ HotKey
- Register HotKey
- VS2010 hotkey
- windows hotkey
- Program of taskbar & hotkey
- [VC++]HotKey热键 - msdn
- 用户自定义HotKey
- windows hotkey overall
- MFC HOTKEY 用法
- HotKey,SendMessage,PostMessage基础
- Some useful Eclipse hotkey
- DHCP 流程
- activity全屏设置
- SIFT算法详解
- ORACLE 过滤重复值SQL语句
- 哈希实现
- [perl]hotkey
- json创建和使用
- 【noip2014提高组】【Day2】【解题报告】
- 随笔--2015.10.22
- cocoapod安装和使用
- AllJoyn SYSTEM ARCHITECTURE
- oracle利用分隔符,组合查询想表达的任何话
- linux系统下的各种串口调试工具
- 【机器学习算法源码阅读】之KNN算法