package MyTk::MyApplication; use Exporter; @ISA = qw(Exporter); #use Tk::MainWindow; #@ISA = qw(Tk::MainWindow); use strict; use English; use File::Path; use File::Basename; use File::Find; use Deps; use Utils; use JFile; use IniFile; #=============================================== # デバッグ関係変数 #=============================================== my $Debug = 0; #=============================================== # 文字コード関係変数 #=============================================== # sjis, euc, jis, noconv, utf8 my $FileSystemCharCode = Deps::FileSystemCharCode(); my $PerlCharCode = Deps::PerlCharCode(); my $MySQLCharCode = Deps::MySQLCharCode(); my $WebCharCode = Deps::WebCharCode(); my $WebCharSet = Deps::WebCharSet(); #=============================================== # スクリプト大域変数 #=============================================== my $LF = Deps::LF(); my $DirectorySeparator = Deps::DirectorySeparator(); my $OS = Deps::OS(); BEGIN { } sub new { my ($module, $path) = @_; my $this = {}; bless $this; $this->{'IniFileVariables'} = {}; return $this; } sub DESTROY { my $this = shift; $this->SaveSetting(); # $this->SUPER::DESTROY(@_); } sub Initialize { my ($this) = @_; #=============================================== # デバッグ関係変数 #=============================================== $this->{'Debug'} = 0; $this->{'DoConfirm'} = 0; #$PrintLevelが大きいほど、情報が詳しくなる $this->{'PrintLevel'} = 0; #=============================================== # 文字コード関係変数 #=============================================== # sjis, euc, jis, noconv, utf8 $this->{'OSCharCode'} = Deps::OSCharCode(); $this->{'FileSystemCharCode'} = Deps::FileSystemCharCode(); $this->{'FileCharCode'} = Deps::FileCharCode(); $this->{'PerlCharCode'} = Deps::PerlCharCode(); $this->{'MySQLCharCode'} = Deps::MySQLCharCode(); $this->{'WebCharCode'} = Deps::WebCharCode(); $this->{'WebCharSet'} = Deps::WebCharSet(); $this->{'stdio'} = new JFile; unless( $this->{'stdio'}->Open("con", "rw", $this->{'OSCharCode'} ) ) { print "Can not open STDIN/STDOUT.\n"; return -1; } #=============================================== # スクリプト大域変数 #=============================================== $this->{'LF'} = Deps::LF(); $this->{'DirectorySeparator'} = Deps::DirectorySeparator(); $this->{'OS'} = Deps::OS(); $this->{'Program'} = basename($0); #=============================================== # プログラム実行情報 #=============================================== # $this->{'StartTime'} = time(); $this->{'StartTime'} = $BASETIME; $this->{'StartDate'} = Utils::BuildDateString($this->{'StartTime'}); $this->{'RemoteIPAddress'} = $ENV{'REMOTE_ADDR'}; return 1; } sub MainLoop { my ($this) = @_; Tk::MainLoop(); } sub AddIniFileVariable { my ($this, $KeyTree, $VarName) = @_; return unless($VarName); my ($section, $key) = ($KeyTree =~ /^\\(.+?)\\(.*)$/); return unless($section); my $pHash = $this->{'IniFileVariables'}; $pHash->{$KeyTree} = $VarName; } sub ReadSetting { my ($this) = @_; my $IniFile = $this->{'IniFile'}; return unless($IniFile); my $pHash = $this->{'IniFileVariables'}; return unless($pHash); foreach my $KeyTree (keys %$pHash) { my $AppKey = $pHash->{$KeyTree}; next unless($AppKey); my ($section, $key) = ($KeyTree =~ /^\\(.+?)\\(.*)$/); next unless($section); #print "kin: $AppKey: $section: $key\n"; my $val = $IniFile->GetString($section, $key, ''); $val = '' unless(defined $val); $this->{$AppKey} = $val; } return 1; } sub SaveSetting { my ($this) = @_; my $IniFile = $this->{'IniFile'}; return unless($IniFile); my $pHash = $this->{'IniFileVariables'}; return unless($pHash); foreach my $KeyTree (keys %$pHash) { my $AppKey = $pHash->{$KeyTree}; next unless($AppKey); my ($section, $key) = ($KeyTree =~ /^\\(.+?)\\(.*)$/); next unless($section); my $val = $this->{$AppKey}; next unless(defined $val); #print "kout: $AppKey: $section: $key: $val\n"; $IniFile->WriteString($section, $key, $val); } return 1; } sub OpenIniFile { my ($this, $ProgramPath, $CreateIniFile) = @_; return $this->{'IniFile'} = new IniFile($ProgramPath, $CreateIniFile); } sub ConnectDocument { my ($this, $doc) = @_; $this->{'Document'} = $doc; } sub Doc { return shift->{'Document'}; } sub IniFile { return shift->{'IniFile'}; } sub Debug { return shift->{'Debug'}; } sub DoConfirm { return shift->{'DoConfirm'}; } sub PrintLevel { return shift->{'PrintLevel'}; } sub OSCharCode { return shift->{'OSCharCode'}; } sub FileSystemCharCode { return shift->{'FileSystemCharCode'}; } sub FileCharCode { return shift->{'FileCharCode'}; } sub PerlCharCode { return shift->{'PerlCharCode'}; } sub MySQLCharCode { return shift->{'PerlChaMySQLCharCoderCode'}; } sub WebCharCode { return shift->{'WebCharCode'}; } sub WebCharSet { return shift->{'WebCharSet'}; } sub stdio { return shift->{'stdio'}; } sub LF { return shift->{'LF'}; } sub DirectorySeparator { return shift->{'DirectorySeparator'}; } sub OS { return shift->{'OS'}; } sub Program { return shift->{'Program'}; } sub ProgramPath { return shift->{'ProgramPath'}; } sub Version { return shift->{'Version'}; } sub Title { return shift->{'Title'}; } sub StartTime { return shift->{'StartTime'}; } sub StartDate { return shift->{'StartDate'}; } sub RemoteIPAddress { return shift->{'RemoteIPAddress'}; } sub SetProgram { my ($this,$p) = @_; return $this->{'Program'} = $p; } sub SetProgramPath { my ($this,$p) = @_; return $this->{'ProgramPath'} = $p; } sub SetVersion { my ($this,$p) = @_; return $this->{'Version'} = $p; } sub SetTitle { my ($this,$p) = @_; return $this->{'Title'} = $p; } sub print { my ($this, @args) = @_; return $this->{'stdio'}->print(@args) if($this->{'stdio'}); return print(@args); } sub DebugPrint { my ($this, @args) = @_; return $this->print(@args) if($this->{'Debug'}); return ''; } 1;