■
前回アップしたバージョンは日本語処理がかなりやばかったのでいろいろ手を尽くした結果、多分日本語が化けないようになった。utf8のコーデックを使用してStreamReader経由でファイルの内容を受け取り、StreamWriter経由で書き込む。Win98系のOSで動作するのかは環境が無いのでわからない。
import os, os.path, string, codecs # command.xml path commandpath = os.path.join( GetAppDir(), "command.xml" ) # get command name commandname = os.path.basename(word) commandname = commandname[0:len(commandname) - 4] # make new XML node string new_node = (" " + chr(60) + "shellexec name='" + commandname + "' ") new_node += ("file='" + word + "' ") new_node += ("directory='" + os.path.dirname(word) + "' ") new_node += ("param='%param' /" + chr(62) + "\n") # encode new_node = unicode(new_node) # file open utf8_codec = codecs.lookup('UTF-8') f = utf8_codec[2] ( file(commandpath, 'rb') ) sbuf = u'' # read file str = f.readline() while str != '': if string.find(str, chr(47) + 'command-group') > -1: str = new_node + str sbuf += str str = f.readline() f.close() # write to file f = utf8_codec[3] ( file(commandpath, 'wb+') ) f.write(sbuf) f.close() # reload command RemoveCommandAll() LoadCommandXML( commandpath )
引数に、登録したい実行ファイルのフルパスを与えると、shellexecコマンドとして登録する。コマンド名は拡張子無しのファイル名。pyファイルにまとめたのをCraftLaunchを応援したいしにアップしたので詳細はそちらを参照のこと。