// バージョン:1.04 // 公開日 :2004.12.13 // 連絡先 :siteCTS // 動作に必要なもの:田楽DLL $ini = macrodir + "\\Nepo104.ini"; //設定ファイルのパス $env = macrodir + "\\NepoEnv104.mac"; //環境設定マクロのパス //パス設定を変更する時は、環境設定マクロも同時に修正する必要があります。 //マクロ開始 call initialize; //マクロ終了 ////// ■ メイン関数群 ■ ////// 基本的に上から下へ実行 // &initialize 初期化 // initialize: disabledraw; $abs = ""; //ファイルの絶対パス $dir = ""; //フォルダの絶対パス $log = ""; //ログに出力するテキスト //Ctrl,Shift,Altが押されていればメニューをキャレット(文字カーソル)に出す if (iskeydown(0x10) || iskeydown(0x11) || iskeydown(0x12)) #menuPosition = 1; //caret else #menuPosition = 0; //mouse //メニュー配列 $menuName[0] = ""; $menuPath[0] = ""; #menuSize = 0; //バッファ #currentX = x; #currentY = y; #selTopX = 0; #selTopY = 0; #selEndX = 0; #selEndY = 0; $sbuffer = searchbuffer; #soption = searchoption; //よく使う設定はグローバル変数に入れておく #log = getininum($ini, "General", "LogMode"); #EnvExpand = getininum($ini, "General", "EnvExpand"); #FolderOpen = getininum($ini, "General", "FolderOpen"); #FileSelect = getininum($ini, "General", "FileSelect"); #hitWebReplace = 0; //Webパス変換にヒットしたら1 //田楽DLLロード loaddll hidemarudir + "\\DengakuDLL.dll"; if (!result) call error "「文字列からファイルを開くマクロ」\n\n田楽DLLのロードに失敗しました。\n" + hidemarudir +" に DengakuDLL.dll があるか確認してください。"; else if (!existfile($ini)) { call question "initialize : 設定ファイルが見つかりません\n\n開こうとした設定ファイルのパス = " + $ini + "\n\n「はい」  … 環境設定ダイアログを開きます。\n「いいえ」 … そのまま終了します。\n\n※初回起動では設定ファイルがないので、「はい」を押してください。"; if (##return) { call message "\"" + $ini + "\" を作ります。\nなにか問題があって設定を初期化したい時は、このファイルを削除してください。\n\n※環境設定マクロはやたら重いので、起動に数秒かかります。(866MHzマシンで約5秒、2.66GHzマシンで約3秒)"; execmacro $env; } freedll; endmacro; } //次へ if (selecting) goto acquirePath; else goto interpretPath; return; //initialize.end // interpretPath パス部分を認識して選択 // interpretPath: if (code == 0x0D) left; if (code == 0x0D) { //2連続改行だった時は空行 right; beginsel; endsel; goto acquirePath; //次へ } if (getininum($ini, "General", "SearchPattern")) { //文頭→文末 searchup "[\"'<>| \n\t]", regular; if (code == '"') $$s = "\""; else if (code == '\'') $$s = "'"; else if (code == '|') $$s = "|"; else if (code == '<') $$s = ">"; else if (code == '>') $$s = "<"; else $$s = " \"'<>|"; $$s = "[" + $$s + "\n\t]"; //選択開始位置調整 if (code == ' ' || code == '"' || code == '\'' || code == '<' || code == '>' || code == 0x0D || code == '\t') right; beginsel; searchdown $$s, regular; endsel; } else { //文末→文頭 searchdown "[\"'<>| \n\t]", regular; if (code == '"') $$s = "\""; else if (code == '\'') $$s = "'"; else if (code == '|') $$s = "|"; else if (code == '<') $$s = ">"; else if (code == '>') $$s = "<"; else $$s = " \"'<|"; $$s = "[" + $$s + "\n\t]"; beginsel; searchup $$s, regular; //選択範囲調整 while (1) { if (code != ' ' && code != '"' && code != '\'' && code != '<' && code != '>' && code != 0x0D && code != '\t') break; right; } endsel; } goto acquirePath; //次へ return; //interpretPath.end // acquirePath パス文字列の取得 // acquirePath: #selTopX = seltopx; #selTopY = seltopy; #selEndX = selendx; #selEndY = selendy; //exitの再選択で使用 $abs = dllfuncstr("LTRIM", dllfuncstr("RTRIM", gettext(seltopx, seltopy, selendx, selendy))); //選択開始が行頭からで、末尾が ) : の時はタグジャンプ if (#selTopX == 0 && (rightstr($abs, 1) == ")" || rightstr($abs, 1) == ":")) { if (#log) call log "acquirePath: タグジャンプコマンドを発行\n\tパス = " + $abs; call exit 4; } //環境設定起動キーワード $$keyword = getinistr($ini, "General", "EnvsetKeyword"); if ($abs == $$keyword && $$keyword != "__EnvsetKeywordDisabled__") { if (#log) call log "acquirePath: 環境設定マクロの起動キーワードにマッチング"; execmacro $env; call exit 1; //取得文字列なし } else if ($abs == "") { if (getininum($ini, "General", "AltCurrentFolder")) { $abs = directory + "\\"; //カレントフォルダを対象にする ##this = 1; } else { if (#log) call log "acquirePath: 取得できる文字列がありません"; call exit 2; } } if (#log) { if (##this) { call log "acquirePath: カレントフォルダを対象に変更\n\t取得した文字列 = なし\n\t変更後のパス = " + $abs; } else { call log "acquirePath: 取得した文字列\n\t" + $abs;}} call replacePath; //パス変換 call envExpand $$return; //環境変数展開 $abs = $$return; //パスにエスケープとしての \\ が含まれる時は \ に置換 if (strstr($abs, "\\\\") != -1) { $$before = $abs; if (leftstr($abs, 4) == "\\\\\\\\") //ネットワークパスで先頭が \\\\ の時は先に // にして置換を避ける $abs = dllfuncstr("GSUB", $abs, "\\\\\\\\", "//", 1); if (leftstr($abs, 2) == "\\\\") //ネットワークパスで先頭が \\ の時は先に // にして置換を避ける $abs = dllfuncstr("GSUB", $abs, "\\\\", "//", 1); $abs = dllfuncstr("GSUB", $abs, "\\\\", "/", -1); //すべての \\ を / へ置換 if (#log) call log "acquirePath: エスケープ文字を検出\n\t変換前のパス = " + $$before + "\n\t変換後のパス = " + $abs; } $abs = dllfuncstr("GSUB", $abs, "\\", "/", -1); //すべての \ を / へ置換 //パス強制認識 if (getininum($ini, "General", "AbsMatchForced")) { ##letter = 0; //ドライブレター分の修正値 if (strstr($abs, "http://") != -1) $$find = "http://"; else if (strstr($abs, "https://") != -1) $$find = "https://"; else if (strstr($abs, "ftp://") != -1) $$find = "ftp://"; else if (strstr($abs, "file://") != -1) $$find = "file://"; else if (strstr($abs, "mailto:") != -1) $$find = "mailto:"; else if (strstr($abs, "../") != -1) $$find = "../"; else if (strstr($abs, "./") != -1) $$find = "./"; else if (strstr($abs, ":/") != -1) { $$find = ":/"; ##letter = 1;} if ($$find != "") { ##n = dllfunc("STRSTR2", $abs, $$find) - ##letter; if (##n > 0) { //パスが先頭にない call substr $abs, ##n; $$after = $$return; if (#log) call log "acquirePath: パス強制認識を適用\n\tキーワード = " + $$find + "\n\t変換前のパス = " + $abs + "\n\t変換後のパス = " + $$after; $menuName[0] = $$after + " として認識(パスを強制認識)"; $menuName[1] = $abs + " として認識(そのまま)"; #menuSize = 2; call showMenu; ##n = ##return; if (##n == 1) $abs = $$after; else if (##n != 2) call exit 3; } } } //JavaScriptやCSSやPerlとかのコメントをパスと勘違いしないように //頭に // があるとネットワークパスと判断する //頭に /* があるとルートパスと勘違いする //頭に # があるとアンカーと勘違いする //"///" は "//" にしてもいい(ただし //remotePC/... 形式のネットワークパスには対応しなくなる) if (leftstr($abs, 3) == "///" || leftstr($abs, 2) == "/*" || leftstr($abs, 1) == "#") { if (#log) call log "acquirePath: コメントアウトかアンカーと判断\n\tパス = " + $abs; call exit 2; } if (strstr($abs, ".") == -1 && midstr($abs, 1, 1) != ":" && rightstr($abs, 1) != "/") { if (#log) call log "acquirePath: パスではない文字列と判断\n\t取得文字列 = " + $abs; call exit 2; } goto createAbsolutePath; //次へ return; //acquirePath.end // createAbsolutePath 絶対パスの生成 // createAbsolutePath: call checkScheme $abs; //URL・メールアドレス・ネットワークパス・すでに絶対パス → そのまま if (##return || leftstr($abs, 2) == "//" || midstr($abs, 1, 2) == ":/") { $abs = $abs; //ルートパス → "ドライブレター+取得したパス" } else if (leftstr($abs, 1) == "/") { $abs = leftstr(directory, 2) + $abs; //カレントフォルダ → ./ を削除して "カレントディレクトリ+取得したパス" } else if (leftstr($abs, 2) == "./") { call substr $abs, 2; $abs = directory + "\\" + $$return; //相対パス → 絶対パスに変換 } else if (strstr($abs, "../") != -1) { //カレントディレクトリのパスを配列へ分割 $$dir[0] = dllfuncstr("GETTOKEN", directory, "\\"); ##n = 1; while (1) { if (!dllfunc("HASMORETOKENS")) break; $$s = dllfuncstr("GETTOKEN", "", "\\"); if ($$s != "") { $$dir[##n] = $$s; ##n = ##n +1; } } ##dirlength = ##n; $$file = dllfuncstr("GSUB", $abs, "../", "", -1); //"../"を削除 ##n = 0; ##stopNum = ##dirlength - dllfunc("STRCOUNT", $abs, "../"); //総階層数−上がる階層数 $abs = ""; //初期化して再生成 while (1) { $abs = $abs + $$dir[##n] + "\\"; ##n = ##n +1; if (##stopNum == ##n) break; } $abs = $abs + $$file; //その他 → "カレントディレクトリ+取得したパス" } else if ($abs != "") { $abs = directory + "/" + $abs; //取得文字列なし } else call exit 2; $abs = dllfuncstr("GSUB", $abs, "\\", "/", -1); //区切りは / に置換しておく if (#log) call log "createAbsolutePath: 取得文字列から生成した絶対パス\n\t" + $abs; goto createMenu; //次へ return; //createAbsolutePath.end // &createMenu ■選択メニュー作成 // createMenu: call clearMenu; //メニューを初期化 call cutFileName $abs; $dir = $$return; call checkScheme $abs; // メールメニュー // if (##return >= 4) { call log "createMenu: メールアドレスと認識しました"; if (getininum($ini, "Mailer", "Use")) { if (##return == 4) { //mailto:を削除 call substr $abs, 7; $abs = $$return; } call replace $abs, "@", "@"; call replace getinistr($ini, "Mailer", "Option"), "$address$", $$return; $abs = $$return; $menuName[0] = "メールを送信 → " + $abs; $menuPath[0] = "__SendMailMenu__"; $menuName[1] = "コマンドラインを修正する"; //メニュー名注意(判別に使用) $menuPath[1] = "__SendMailMenu__"; $menuName[2] = "メーラーを起動"; //メニュー名注意 $menuPath[2] = "__SendMailMenu__"; #menuSize = 3; goto executeMenu; } // Webパスメニュー // } else if (##return) { if (getininum($ini, "ExtensionList", "AllCorrelation")) //全部関連付けの時は直 call appRun "", "", $abs; //exit call log "createMenu: Webパスと認識しました"; call appendMenu "Browser"; goto executeMenu; // ファイラメニュー // パスの末尾が / の時はファイラ } else if (rightstr($abs, 1) == "/") { call log "createMenu: フォルダのパスと認識しました"; call existFolder $dir; //存在チェック call appendMenu "Filer"; call appendMenu "FileSelectMenu"; goto executeMenu; // クエリ選択メニュー // "../?query" などファイル名がなくてクエリかアンカーがある時 } else if (strstr($abs, "/?") != -1 || strstr($abs, "/#") != -1) { call cutQueryString $abs; $menuName[#menuSize] = "クエリをカットしてファイラで開く → " + $$return; $menuPath[#menuSize] = $$return; #menuSize = #menuSize +1; call replacePath "Web"; //Webパス変換 if (#hitWebReplace) { //ヒットがあれば追加 $menuName[#menuSize] = "Webパスに変換してブラウザで開く → " + $$return; $menuPath[#menuSize] = $$return; #menuSize = #menuSize +1; } call appendMenu "FileSelectMenu"; goto executeMenu; } //以下はファイル名があるので存在チェック if (!existfile($abs)) { call cutQueryString $abs; if (!existfile($$return)) { //クエリをカットして再挑戦 if (#log) call log "createMenu: ファイルが存在しません。\n\tパス = " + $abs; call exit 2; } } //拡張子ごとの分岐 call checkExt $abs; $$res = $$return; if (#log) call log "createMenu: 拡張子ごとの分岐判定\n\t" + $$res; // Webパス変換メニュー // エディタかブラウザを選択 html,xht,cgi,shtml if ($$res == "Webパス変換") { $$webpath = $abs; call cutQueryString $abs; $$abs = $$return; $menuName[0] = "エディタで開く"; $menuPath[0] = $$abs; $menuName[1] = "ブラウザで開く"; $menuPath[1] = $$abs; #menuSize = 2; call replacePath "Web"; //Webパス変換 if (#hitWebReplace) { //ヒットがあれば追加 $menuName[2] = "ブラウザで開く → " + $$return + " (Webパス変換)"; $menuPath[2] = $$return; #menuSize = 3; } call appendMenu "FolderOpenMenu"; call appendMenu "CorrelationMenu"; call appendMenu "FileSelectMenu"; call showMenu; ##n = ##return; if (!##n) call exit 3; ##n = ##n -1; if (##n == 0) { $abs = $menuPath[##n]; call appendMenu "Editor"; } else if (##n == 1) { $abs = $menuPath[##n]; call appendMenu "Browser"; } else if (##n == 2 && #hitWebReplace) { //ヒットがあれば追加メニューが入ってる $abs = $menuPath[##n]; call appendMenu "Browser"; } else if (strstr($menuPath[##n], "Menu__") != -1) { call executeMenu ##n; //オプションメニューはexecuteMenuで拾う } // その他のメニュー // } else if ($$res == "エディタ") call appendMenu "Editor"; else if ($$res == "ブラウザ") call appendMenu "Browser"; else if ($$res == "ビューア") call appendMenu "Viewer"; else if ($$res == "プレイヤー") call appendMenu "Player"; // 関連付け // else if ($$res == "関連付け") { if (getininum($ini, "ExtensionList", "CorrelationNoMenu")) //他のメニューを出さない call appRun "", "", $abs; //exit //パスではない } else if ($$res == "登録なし") call exit 2; //拡張子なし else call exit 2; call appendMenu "CorrelationMenu"; call appendMenu "FolderOpenMenu"; call appendMenu "FileSelectMenu"; goto executeMenu; //次へ return; //createMenu.end // &executeMenu ■実行 // 選択したメニューを実行 executeMenu: if (##1) //先にメニューを出してる時は引数有 ##n = ##1; else { call showMenu; ##n = ##return; if (!##n) call exit 3; ##n = ##n -1; //メニューは1から、配列は0から始まるので-1 } call log "executeMenu: 選択されたメニューのパラメータ\n\t選択番号 = " + str(##n) + "\n\tmenuName = " + $menuName[##n] + "\n\tmenuPath = " + $menuPath[##n]; if ($menuPath[##n] == "__CancelMenu__") { call exit 3; // ファイル検索 // } else if ($menuPath[##n] == "__FileSelectMenu__") { call existFolder $dir; call clearMenu; call replace $dir, "/", "\\"; call chop $$return; //尻の区切り子を削除 $$file = dllfuncstr("GETFILENAME", hidemaruhandle(0), "ファイルの参照(複数選択不可)", $$return, ""); if ($$file == "") call exit 3; if (strstr($$file, "|") != -1) { //複数選択された時は最初のひとつに絞る $$s = dllfuncstr("GETTOKEN", $$file, "|"); $$file = $$s; //フォルダ $$s = dllfuncstr("GETTOKEN", "", "|"); $$file = $$file + "\\" + $$s; //フォルダ+最初のファイル } call replace $$file, "\\", "/"; $abs = $$return; call cutFileName $abs; //フォルダを変更された時の対策 $dir = $$return; goto createMenu; //メニュー生成に戻る // フォルダオープン // } else if ($menuPath[##n] == "__FolderOpenMenu__") { call cutFileName $abs; $abs = $$return; goto createMenu; //メニュー生成に戻る // メール送信 // } else if ($menuPath[##n] == "__SendMailMenu__") { if ($menuName[##n] == "メーラーを起動") $abs = ""; else { //送信・修正 if ($menuName[##n] == "コマンドラインを修正する") $abs = input("コマンドラインを修正", $abs); if ($abs == "") call exit 3; } call envExpand getinistr($ini, "Mailer", "Path"), 1; //強制展開 call appRun "メール", $$return, $abs; //次へ // 関連付けに従う // } else if ($menuPath[##n] == "__CorrelationMenu__") { call appRun "", "", $abs; //次へ // クエリ選択→ファイラで開く // } else if (strstr($menuName[##n], "クエリをカットしてファイラで開く") != -1) { $abs = $menuPath[##n]; goto createMenu; //再帰 // クエリ選択→Webパスに変換してブラウザで開く // ヒット時のみ出現 } else if (strstr($menuName[##n], "Webパスに変換してブラウザで開く") != -1) { $abs = $menuPath[##n]; call clearMenu; call appendMenu "Browser"; call appendMenu "FolderOpenMenu"; call appendMenu "FileSelectMenu"; goto executeMenu; //再帰 } call appRun $menuName[##n], $menuPath[##n], $abs; //次へ return; //executeMenu.end // appRun アプリケーションの起動 // appRun: if ($$2 != "" && str(strstr($$2, "\"")) == "-1") $$2 = "\"" + $$2 + "\""; $$appName = $$1; $$appPath = $$2; $abs = $$3; if ($$appName == "メール") ##scheme = 5; else { call checkScheme $abs; ##scheme = ##return; } if (!##scheme) { //file: call cutQueryString $abs; //JSなどにクエリが付いてる時の対策 $abs = dllfuncstr("GSUB", $$return, "/", "\\", -1); // \ でないと動かないソフトがあるので置換しておく if (rightstr($abs, 1) != "\\" && str(existfile($abs)) == "0") { if (#log) call log "appRun: ファイルが存在しません\n\tパス = " + $abs; call exit 3; } else $abs = "\"" + $abs + "\""; } if (#log) call log "appRun: \n\t$$appName = " + $$appName + "\n\t実行ファイルのパス = " + $$appPath + "\n\tコマンドライン = " + $abs; if ($$appPath == "" && $abs != "") ##r = dllfunc("RUN", $abs); //関連付けで起動 else if ($$appPath != "" && $abs == "") ##r = dllfunc("RUN", $$appPath); //アプリケーションのみ起動 else if ($$appPath != "" && $abs != "") ##r = dllfunc("RUN", $$appPath + " " + $abs); else if (#log) call log "appRun: 条件分岐がおかしいです?"; if (##r) call exit 1; else call exit 2; return; //appRun.end // e&xit 終了処理 // exit: escape; moveto #currentX, #currentY; //##1 : 0=強制終了, 1=正常終了, 2=パスではない, 3=処理中止, 4=タグジャンプ if (##1) { if (##1 == 1 && getininum($ini, "General", "OkSelect")) ##f = 2; else if (##1 == 3 && getininum($ini, "General", "CancelSelect")) ##f = 2; else ##f = ##1; if (##f == 2) { //パスではなかった時 ##ExitSelect = getininum($ini, "General", "ExitSelect"); if (##ExitSelect == 1) { //選択範囲そのまま moveto #selTopX, #selTopY; beginsel; moveto #selEndX, #selEndY; endsel; } else if (##ExitSelect == 2) { //単語選択 selectword; endsel; } if (##1 == 2 && getininum($ini, "General", "ExitExecMacro")) { //指定マクロを実行 $$macro = getinistr($ini, "General", "ExitExecMacroFile"); if (strstr($$macro, "\\") == -1) //ファイル名だけの時はフルパスにする $$macro = macrodir + "\\" + $$macro; execmacro $$macro; if (#log) call log "exit: マクロを実行\n\t実行したマクロ = " + $$macro; } } } //ログファイル出力 if (#log) { $$log = getinistr($ini, "General", "LogFile"); if ($$log != "") { call envExpand $$log, 1; $$log = $$return; writeinistr $$log, "log", 0, 0; writeinistr $$log, "log", "date", " " + date + " " + time + "\n"; ##i = 0; while (##i < #logSize) { writeinistr $$log, "log", "log" + str(##i), " " + $log[##i] + "\n"; ##i = ##i +1; } if (!##1) $$s = "強制終了"; else if (##1 == 1) $$s = "正常終了"; else if (##1 == 2) $$s = "パスではない文字列と判断"; else if (##1 == 3) $$s = "処理中止"; else if (##1 == 4) $$s = "タグジャンプ"; writeinistr $$log, "log", "exit", " 終了パラメータ : " + str(##1) + "(" + $$s + ")"; } } if (##f == 4) //タグジャンプするとDLLが解放される? tagjump; freedll; setsearch $sbuffer, #soption; //検索条件を復元 endmacro; //exit.end ////// ■ サブ関数群 ■ ////// //ログに記録する文字列 log: $log[#logSize] = $$1; #logSize = #logSize +1; return; // envExpand 環境変数の展開 // GETTOKENだとかえって効率悪い(変数内で正規表現が使えればなぁ) envExpand: if (dllfunc("STRCOUNT", $$1, "%") < 2 || (#EnvExpand == 0 && ##2 != 1)) return $$1; $$path = $$1; while (1) { $$temp = $$path; //加工するのでパスをコピーする ##spos = strstr($$temp, "%"); //最初の%を検索 $$temp = dllfuncstr("GSUB", $$temp, "%", "", 1); //最初の%を削除 ##epos = strstr($$temp, "%"); //次の%を検索 $$temp = dllfuncstr("GSUB", $$temp, "%", "", 1); //次の%を削除 ##strings = ##epos - ##spos; //%〜%間の文字数 $$envstr = midstr($$temp, ##spos, ##strings); //環境変数と思われる文字列を抽出 $$expandstr = getenv($$envstr); //展開してみる if ($$expandstr != "") { if (#log) call log "envExpand: 環境変数の展開にマッチング\n\t展開前の環境変数 = %" + $$envstr + "%\n\t展開後の環境変数 = " + $$expandstr; call replace $$path, "%" + $$envstr + "%", $$expandstr; //展開できたら%ごと置換 } else { //展開できなかったらスキップマークに置換 call replace $$path, "%" + $$envstr + "%", "::::" + $$envstr + "::::"; } $$path = $$return; if (dllfunc("STRCOUNT", $$path, "%") < 2) //パスに含まれる%が1個以下になったら終了 break; } return dllfuncstr("GSUB", $$path, "::::", "%", -1); //スキップマークを元に戻す //envExpand.end // &replacePath パス変換 // call=createAbsolutePath replacePath: $$key = "Replace" + $$1 + "Path"; //Webパス変換の時は$$1="Web" $$abs = $abs; if (!getininum($ini, $$key, "Use")) return $$abs; ##hit = 0; ##i = 0; while (1) { $$before = getinistr($ini, $$key, "Befor" + str(##i)); $$after = getinistr($ini, $$key, "After" + str(##i)); if ($$before == "" || $$after == "") break; else { $$absLeft = dllfuncstr("TOLOWER", leftstr($$abs, strlen($$before))); //beforeと同じ文字数を切り出し if ($$absLeft == dllfuncstr("TOLOWER", $$before)) { $$absBefore = $$abs; $$abs = dllfuncstr("GSUB", $$abs, $$absLeft, $$after, 1); //absのbefore部分をafterへ置換 ##hit = 1; break; } } ##i = ##i +1; } #hitWebReplace = 0; //複数箇所から呼ばれるので初期化しておく(グローバル) if (##hit) { if ($$1 == "Web") #hitWebReplace = 1; if (#log) call log "replacePath: 取得したパスが" + $$1 + "パス変換の設定にマッチング\n\tマッチした設定 = " + $$before + ">" + $$after + "\n\t変換前のパス = " + $$absBefore + "\n\t変換後のパス = " + $$abs; } return $$abs; //replacePath.end // &appendMenu メニュー配列作成 // appendMenu: //キャンセル if ($$1 == "CancelMenu") { $menuName[#menuSize] = "やめる"; $menuPath[#menuSize] = "__" + $$1 + "__"; #menuSize = #menuSize +1; //関連付けメニュー } else if ($$1 == "CorrelationMenu") { $menuName[#menuSize] = "関連付けに従って開く"; $menuPath[#menuSize] = "__CorrelationMenu__"; #menuSize = #menuSize +1; //フォルダを開く } else if ($$1 == "FolderOpenMenu") { if (#FolderOpen) { $menuName[#menuSize] = "フォルダを開く → " + $dir; $menuPath[#menuSize] = "__" + $$1 + "__"; #menuSize = #menuSize +1; } //他のファイルを開く } else if ($$1 == "FileSelectMenu") { if (#FileSelect) { $menuName[#menuSize] = "他のファイルを開く"; $menuPath[#menuSize] = "__" + $$1 + "__"; #menuSize = #menuSize +1; } //アプリケーション } else { //Filer, Editor, Browser, Viewer, Player ##i = 0; ##j = ##i; while (##i < 10) { $$name = getinistr($ini, $$1, "Name" + str(##i)); $$path = getinistr($ini, $$1, "Path" + str(##i)); if ($$name != "" && $$path != "") { $menuName[##j] = $$name; call envExpand $$path, 1; //強制展開 $menuPath[##j] = $$return; ##j = ##j +1; #menuSize = ##j; } ##i = ##i +1; } } return; //appendMenu.end // showMenu メニュー表示 // showMenu: // if ($menuName[1] == "" && str(##1) != "1") //選択メニューがひとつしかない時はそのまま開く // ##n = 1; // // else { //選択メニューが複数ある時はメニュー表示 call appendMenu "CancelMenu"; enabledraw; if (#menuPosition) { moveto #currentX, #currentY; //もとのカーソル位置にメニューを表示 menuarray $menuName, #menuSize; } else { moveto #selTopX, #selTopY; //マウスの時は関係ないので認識範囲を再選択 beginsel; moveto #selEndX, #selEndY; endsel; mousemenuarray $menuName, #menuSize; } ##n = result; disabledraw; // } return ##n; //showMenu.end // clearMenu メニュー配列を消去 // clearMenu: // ##i = 0; // while (##i < #menuSize +1) { // $menuName[##i] = ""; // $menuPath[##i] = ""; // ##i = ##i +1; // } #menuSize = 0; return; //clearMenu.end // checkExt 拡張子ごとの動作判定 // checkExt: //クエリをカットして拡張子を取得 call cutQueryString $abs; $$abs = $$return; call lastIndexOf $$abs, "."; if (##return == -1) return ""; call substr $$abs, ##return +1; $$ext = $$return; if (#log) call log "checkExt: パスから取得された拡張子\n\tパス = " + $abs + "\n\t拡張子 = " + $$ext; if (getininum($ini, "ExtensionList", "AllCorrelation")) return "関連付け"; call listExist getinistr($ini, "ExtensionList", "SelectExt"), $$ext; if (##return) return "Webパス変換"; call listExist getinistr($ini, "ExtensionList", "EditorExt"), $$ext; if (##return) return "エディタ"; call listExist getinistr($ini, "ExtensionList", "BrowserExt"), $$ext; if (##return) return "ブラウザ"; call listExist getinistr($ini, "ExtensionList", "ViewerExt"), $$ext; if (##return) return "ビューア"; call listExist getinistr($ini, "ExtensionList", "PlayerExt"), $$ext; if (##return) return "プレイヤー"; if (getininum($ini, "ExtensionList", "OtherCorrelation")) //登録なしでは関連付けに従う return "関連付け"; else { call listExist getinistr($ini, "ExtensionList", "CorrelationExt"), $$ext; if (##return) return "関連付け"; } return "登録なし"; //checkExt.end ////// ■ 汎用関数群 ■ ////// question: enabledraw; question $$1; disabledraw; return result; message: enabledraw; message $$1; disabledraw; return; error: call message $$1; call exit; return; //$$1=リスト, $$2=検索される文字列, $$3=区切り子, ##4=無変換フラグ listExist: if ($$3 == "") $$3 = " "; if (!##4) { $$1 = dllfuncstr("TOLOWER", $$1); $$2 = dllfuncstr("TOLOWER", $$2); } $$s = dllfuncstr("GETTOKEN", $$1, $$3); while (1) { if ($$s == $$2) return 1; if (!dllfunc("HASMORETOKENS")) break; $$s = dllfuncstr("GETTOKEN", "", $$3); } return 0; checkScheme: if (leftstr($$1, 5) == "http:") return 1; else if (leftstr($$1, 6) == "https:") return 2; else if (leftstr($$1, 4) == "ftp:") return 3; else if (leftstr($$1, 7) == "mailto:") return 4; else if ((strstr($$1, "@") != -1 || strstr($$1, "@") != -1) && strstr($$1, ".") != -1) { //@ . が含まれる if (strstr($$1, " ") == -1 && strstr($$1, "\\") == -1 && strstr($$1, "/") == -1) { //空白 \ / が含まれない call lastIndexOf $$1, "."; if ( (dllfunc("STRCOUNT", $$1, "@") == 1 && strstr($$1, "@") < ##return) || (dllfunc("STRCOUNT", $$1, ";") == 1 && strstr($$1, ";") < ##return) ) return 5; //@ ; がひとつで最後の . が @ ; より後ろにある } } return 0; existFolder: call replace $$1, "/", "\\"; ##n = dllfunc("ENUMDIR", $$return); $$dir = dllfuncstr("FINDNEXT"); if ($$dir == "") { //$$dir = 最後のフォルダ名 call log "existFolder: フォルダが存在しません\n\tパス = " + $$dir; call exit 2; } return 1; cutFileName: call cutQueryString $$1; call lastIndexOf $$return, "/"; call substr $$1, 0, ##return +1; return $$return; cutQueryString: if (strstr($$1, "?") != -1) { //クエリカット call subleft $$1, "?"; $$1 = $$return; } if (strstr($$1, "#") != -1) { //アンカーカット call subleft $$1, "#"; $$1 = $$return; } return $$1; replace: if (!##4) ##4 = -1; return dllfuncstr("GSUB", $$1, $$2, $$3, ##4); lastIndexOf: return dllfunc("STRRSTR2", $$1, $$2); substr: if (!##3) ##3 = dllfunc("STRLEN2", $$1) - ##2; return dllfuncstr("MIDSTR2", $$1, ##2, ##3); subleft: return dllfuncstr("LEFTSTR2", $$1, dllfunc("STRSTR2", $$1, $$2)); subright: ##n = dllfunc("STRSTR2", $$1, $$2); return dllfuncstr("MIDSTR2", $$1, ##n + dllfunc("STRLEN2", $$2), dllfunc("STRLEN2", $$1) - ##n); chop: return dllfuncstr("MIDSTR2", $$1, 0, dllfunc("STRLEN2", $$1) -1);