[475] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[3] | 3 | #include "common.h"
|
---|
| 4 |
|
---|
| 5 | CHistory::CHistory(int BaseID){
|
---|
| 6 | iNum=0;
|
---|
| 7 | iMaxHistoryNum=15;
|
---|
| 8 |
|
---|
| 9 | m_BaseID=BaseID;
|
---|
| 10 | }
|
---|
| 11 | CHistory::~CHistory(){
|
---|
| 12 | int i;
|
---|
| 13 | for(i=0;i<iNum;i++){
|
---|
| 14 | HeapDefaultFree(lpszPath[i]);
|
---|
| 15 | }
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | void CHistory::load(char *path){
|
---|
| 19 | char temporary[MAX_PATH];
|
---|
| 20 |
|
---|
| 21 | char *buffer;
|
---|
| 22 | buffer=ReadBuffer_NonErrMsg(path);
|
---|
| 23 | if(buffer){
|
---|
| 24 | int i;
|
---|
| 25 | i=0;
|
---|
| 26 | while(buffer[i]){
|
---|
| 27 | //表示名
|
---|
| 28 | i=GetOneParameter(buffer,i,temporary);
|
---|
| 29 | if(temporary[0]=='\0') break;
|
---|
| 30 |
|
---|
| 31 | if(buffer[i]=='\r'&&buffer[i+1]=='\n'){
|
---|
| 32 | i+=2;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | add(temporary);
|
---|
| 36 | }
|
---|
| 37 | HeapDefaultFree(buffer);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | void CHistory::save(char *path){
|
---|
| 41 | char *buffer;
|
---|
| 42 | buffer=(char *)HeapAlloc(hHeap,0,iNum*MAX_PATH+1);
|
---|
| 43 | buffer[0]=0;
|
---|
| 44 |
|
---|
| 45 | int i;
|
---|
| 46 | for(i=0;i<iNum;i++){
|
---|
| 47 | sprintf(buffer+lstrlen(buffer),"%s\r\n",lpszPath[i]);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | WriteBuffer(path,buffer,lstrlen(buffer));
|
---|
| 51 |
|
---|
| 52 | HeapDefaultFree(buffer);
|
---|
| 53 | }
|
---|
| 54 | void CHistory::add(char *path){
|
---|
| 55 | lpszPath[iNum]=(char *)HeapAlloc(hHeap,0,lstrlen(path)+1);
|
---|
| 56 | lstrcpy(lpszPath[iNum],path);
|
---|
| 57 | iNum++;
|
---|
| 58 | }
|
---|
[625] | 59 | void CHistory::insert(const char *path){
|
---|
[3] | 60 | //重複チェック
|
---|
| 61 | int i;
|
---|
| 62 | for(i=0;i<iNum;i++){
|
---|
| 63 | if(lstrcmpi(path,lpszPath[i])==0) break;
|
---|
| 64 | }
|
---|
| 65 | if(i==iNum){
|
---|
| 66 | //ローテーション
|
---|
| 67 | for(i=iNum;i>0;i--){
|
---|
| 68 | lpszPath[i]=lpszPath[i-1];
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | if(iNum+1 == iMaxHistoryNum){
|
---|
| 72 | //一番古い情報を削除
|
---|
| 73 | HeapDefaultFree(lpszPath[iNum]);
|
---|
| 74 | }
|
---|
| 75 | else iNum++;
|
---|
| 76 | }
|
---|
| 77 | else{
|
---|
| 78 | //ローテーション
|
---|
| 79 | HeapDefaultFree(lpszPath[i]);
|
---|
| 80 |
|
---|
| 81 | for(;i>0;i--){
|
---|
| 82 | lpszPath[i]=lpszPath[i-1];
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | lpszPath[0]=(char *)HeapAlloc(hHeap,0,lstrlen(path)+1);
|
---|
| 87 | lstrcpy(lpszPath[0],path);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | void CHistory::ResetFileMenu(CSubMenuEx *pobj_SubMenu,BOOL bOwnerDraw){
|
---|
| 91 | //古いメニューアイテムを消去
|
---|
| 92 | while(0<pobj_SubMenu->iMenuItemNum){
|
---|
| 93 | pobj_SubMenu->RemoveItem(0);
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | if(iNum==0){
|
---|
| 97 | //なし
|
---|
| 98 | pobj_SubMenu->InsertItem(0,100,"なし");
|
---|
| 99 | pobj_SubMenu->EnableItem(100,MF_BYCOMMAND|MF_GRAYED);
|
---|
| 100 | return;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 | int i;
|
---|
| 105 | for(i=0;i<iNum;i++){
|
---|
| 106 | //挿入
|
---|
| 107 | pobj_SubMenu->InsertItem(i,m_BaseID+i,lpszPath[i]);
|
---|
| 108 |
|
---|
[631] | 109 | //アイコンをセット(ネットワークドライブ内のファイルは取得に時間がかかるため、除外する)
|
---|
| 110 | if( !Jenga::Common::Path( lpszPath[i] ).IsNetworkPath() )
|
---|
| 111 | {
|
---|
| 112 | if(IsExistFile(lpszPath[i])){
|
---|
| 113 | SHFILEINFO shfi;
|
---|
| 114 | SHGetFileInfo( lpszPath[i], FILE_ATTRIBUTE_ARCHIVE, &shfi, sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SMALLICON );
|
---|
[3] | 115 |
|
---|
[631] | 116 | if(shfi.hIcon){
|
---|
| 117 | pobj_SubMenu->SetIcon(m_BaseID+i,shfi.hIcon);
|
---|
| 118 | }
|
---|
[3] | 119 | }
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | }
|
---|