; 2005/10/30 dokas_mg (update 2007/08/25) #NoEnv #SingleInstance ignore ; (環境依存) デフォルトのドライブのパス drivepath = Q:\ ; (環境依存) デフォルトのリストのパス listpath = C:\BackUpFiles\List_Media-File.txt driveready = false listready = false ; GUI作成 DriveGet, s, List, CDROM ddstr = Loop, Parse, s { path = %A_LoopField%:\ ddstr = %ddstr%%path%| if path=%drivepath% { ddstr = %ddstr%| } } Gui, Add, DropDownList, Vddlist Gddlist xm, %ddstr% Gui, Add, Text, Vtext_drivestatus xp+200 yp+4 W500, 状態 Gui, Add, ListView, Vlistview_drive xm W800 R10 Grid -LV0x10 AddListViewCol() GuiControl, Disable, listview_drive Gui, Add, Button, Vbutton_addmedia Gbutton_addmedia xm W160 Default, データを追加(&R) GuiControl, Disable, button_addmedia Gui, Add, Text, xm, ↓ Gui, Add, Text, Vtext_listpath xm W600, %listpath% Gui, Add, Text, Vtext_listcount xm W600, 登録数 Gui, Add, Button, Gbutton_selectdata xp+640 yp-16 W160, リストファイル変更(&F) Gui, Add, ListView, Vlistview_mediafile xm W800 R20 Grid -LV0x10 AddListViewCol() GuiControl, Disable, listview_mediafile Gui, Add, Button, Vbutton_savedata Gbutton_savedata xm W160, リストファイル上書き保存(&S) GuiControl, Disable, button_savedata listready := LoadMediaFileData(listpath) Gui, Show driveready := LoadDrive(drivepath) If listready & driveready { GuiControl, Enable, button_addmedia } Return GuiClose: GuiEscape: ExitApp ddlist: GuiControlGet, s, , ddlist driveready := LoadDrive(s) GuiControl, Text, text_drivepath, %s% drivepath := s If listready & driveready { GuiControl, Enable, button_addmedia } Return button_addmedia: If CheckDup() = false Return CopyDriveToMediaFile() Return CopyDriveToMediaFile() { GuiControl, -Redraw, listview_mediafile Gui, ListView, listview_drive n := LV_GetCount() Loop, %n% { Gui, ListView, listview_drive LV_GetText(serial, A_Index, 1) LV_GetText(vlabel, A_Index, 2) LV_GetText(fsize, A_Index, 3) LV_GetText(ftime, A_Index, 4) LV_GetText(fname, A_Index, 5) Gui, ListView, listview_mediafile LV_Add("", serial, vlabel, fsize, ftime, fname) } Gui, ListView, listview_mediafile c := LV_GetCount() GuiControl, +Redraw, listview_mediafile GuiControl, Text, text_listcount, 登録数 %c% } CheckDup() { Gui, ListView, listview_drive LV_GetText(serial, 1) Gui, ListView, listview_mediafile dup = false n := LV_GetCount() Loop, %n% { LV_GetText(s, A_Index) If s = %serial% { dup = true Break } } If dup = true { Gui, +OwnDialogs MsgBox, 260, , すでに記録されています`r`n`r`n消去して新たに追加しますか? IfMsgBox, Yes { DeleteDup(serial) Return true } Return false } Return true } DeleteDup(serial) { Gui, ListView, listview_mediafile GuiControl, -Redraw, listview_mediafile c := LV_GetCount() Loop, %c% { n := c - A_Index + 1 LV_GetText(s, n) If s = %serial% LV_Delete(n) } GuiControl, +Redraw, listview_mediafile } button_selectdata: Gui, +OwnDialogs FileSelectFile, s, 3, %listpath%, リストファイル選択, If s <> { listready := LoadMediaFileData(s) GuiControl, Text, text_listpath, %s% listpath := s } If listready & driveready { GuiControl, Enable, button_addmedia } Return button_savedata: s = %listpath%.tmp%A_Now% FileMove, %listpath%, %s%, 1 SaveMediaFileData(listpath) FileDelete %s% Return AddListViewCol() { LV_InsertCol(1, "100", "[シリアルNo]") LV_InsertCol(2, "100", "ボリュームラベル") LV_InsertCol(3, "100 Integer", "サイズ") LV_InsertCol(4, "100", "更新日時") LV_InsertCol(5, "400", "ファイル名") } LoadDrive(path) { GuiControl, Enable, listview_drive Gui, ListView, listview_drive GuiControl, -Redraw, listview_drive LV_Delete() Gui, +OwnDialogs SplashTextOn, 320, 60, MediaList.ahk, `nドライブ%drivepath%の情報取得中 DriveGet, s, Status, %path% SplashTextOff If s<>Ready { GuiControl, Disable, listview_drive GuiControl, Disable, button_addmedia GuiControl, Text, text_drivestatus, ドライブの準備ができていません GuiControl, +Redraw, listview_drive Return false } DriveGet, label, Label, %path% SetFormat, Integer, H DriveGet, serial, Serial, %path% StringTrimLeft, serial, serial, 2 serial = 00000000%serial% SetFormat, Integer, D StringRight, str2, serial, 4 StringTrimRight, serial, serial, 4 StringRight, str1, serial, 4 StringUpper, str1, str1 StringUpper, str2, str2 serial = [%str1%-%str2%] tmpfile = %A_ScriptDir%\drive_tmp%A_Now%.txt RunWait, %ComSpec% /c dir /s /b %path% > %tmpfile%, , Hide Loop, Read, %tmpfile% { FileGetSize, fsize, %A_LoopReadLine% If fsize>0 { FileGetTime, ftime, %A_LoopReadLine%, M FormatTime, timestr, %ftime%, yyyy/MM/dd HH:mm fname := PathFindFileName(A_LoopReadLine) LV_Add("", serial, label, fsize, timestr, fname) } } LV_ModifyCol() GuiControl, Text, text_drivestatus, ドライブ情報読み込み完了 FileDelete %tmpfile% GuiControl, +Redraw, listview_drive Return true } LoadMediaFileData(path) { IfNotExist, %path% { GuiControl, Disable, listview_mediafile GuiControl, Disable, button_savedata Return false } GuiControl, Enable, listview_mediafile GuiControl, -Redraw, listview_mediafile Gui, ListView, listview_mediafile LV_Delete() Loop, Read, %path% { StringSplit, s, A_LoopReadLine, %A_Tab% StringReplace, s3, s3, _, , All LV_Add("", s1, s2, s3, s4, s5) } LV_ModifyCol() GuiControl, +Redraw, listview_mediafile GuiControl, Enable, button_savedata c := LV_GetCount() GuiControl, Text, text_listcount, 登録数 %c% Return true } SaveMediaFileData(path) { Gui, ListView, listview_mediafile c := LV_GetCount() Loop, %c% { LV_GetText(str, A_Index, 1) LV_GetText(s, A_Index, 2) str = %str%%A_Tab%%s% LV_GetText(s, A_Index, 3) s = __________%s% StringRight, s, s, 10 str = %str%%A_Tab%%s% LV_GetText(s, A_Index, 4) str = %str%%A_Tab%%s% LV_GetText(s, A_Index, 5) str = %str%%A_Tab%%s%`r`n FileAppend, %str%, %path% } } ; ダメ文字対応パス関数 PathFindFileName(v) { Return DllCall("SHLWAPI.DLL\PathFindFileNameA", Str, v, Str) }