summaryrefslogtreecommitdiffstats
path: root/src/AutoSaveDlg.cpp
blob: 94bd6530792bcf86264455991b8d22c0190902b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//******************************************************************************
// MIDIシーケンサーソフト『世界樹』
// 自動保存ダイアログクラス
// (C)2002-2012 おーぷんMIDIぷろじぇくと/くず
//******************************************************************************

/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */

/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU */
/* Lesser General Public License for more details. */

/* You should have received a copy of the GNU Lesser General Public */
/* License along with this library; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


#include "winver.h"
#include <afxwin.h>
#include <afxcmn.h>
#include "resource.h"
#include "AutoSaveDlg.h"

#ifndef CLIP
#define CLIP(A,B,C) ((B)<(A)?(A):((B)>(C)?(C):(B)))
#endif


//------------------------------------------------------------------------------
// 構築と破壊
//------------------------------------------------------------------------------

// コンストラクタ
CAutoSaveDlg::CAutoSaveDlg () : CDialog (CAutoSaveDlg::IDD) {
	m_nOn = 0;
	m_lInterval = 0;
	m_nDisableWhilePlaying = 0;
	m_nDisableWhileRecording = 0;
}

//------------------------------------------------------------------------------
// オペレーション
//------------------------------------------------------------------------------

// 『自動保存間隔』の値範囲設定(1〜120[分])
BOOL CAutoSaveDlg::SetIntervalRange () {
	((CSpinButtonCtrl*)GetDlgItem (IDC_AUTOSAVE_INTERVALSP))->SetRange (1, 120);
	((CSpinButtonCtrl*)GetDlgItem (IDC_AUTOSAVE_INTERVALSP))->SetPos (CLIP (1, m_lInterval, 120));
	return TRUE;
}

// 『自動保存間隔』を更新
BOOL CAutoSaveDlg::UpdateInterval () {
	int nOn = ((CButton*)GetDlgItem (IDC_AUTOSAVE_ON))->GetCheck ();
	GetDlgItem (IDC_AUTOSAVE_INTERVAL)->EnableWindow (nOn);
	GetDlgItem (IDC_AUTOSAVE_INTERVALSP)->EnableWindow (nOn);
	return TRUE;
}

// 『演奏中は自動保存しない』を更新
BOOL CAutoSaveDlg::UpdateDisableWhilePlaying () {
	int nOn = ((CButton*)GetDlgItem (IDC_AUTOSAVE_ON))->GetCheck ();
	GetDlgItem (IDC_AUTOSAVE_DISABLEWHILEPLAYING)->EnableWindow (nOn);
	return TRUE;
}

// 『リアルタイム入力中は自動保存しない』を更新
BOOL CAutoSaveDlg::UpdateDisableWhileRecording () {
	int nOn = ((CButton*)GetDlgItem (IDC_AUTOSAVE_ON))->GetCheck ();
	GetDlgItem (IDC_AUTOSAVE_DISABLEWHILERECORDING)->EnableWindow (nOn);
	return TRUE;
}


//------------------------------------------------------------------------------
// オーバーライド
//------------------------------------------------------------------------------

// データエクスチェンジ
void CAutoSaveDlg::DoDataExchange (CDataExchange* pDX) {
	CDialog::DoDataExchange (pDX);
	DDX_Check (pDX, IDC_AUTOSAVE_ON, m_nOn);
	DDX_Text (pDX, IDC_AUTOSAVE_INTERVAL, m_lInterval);
	DDV_MinMaxInt (pDX, m_lInterval, 1, 120);
	DDX_Check (pDX, IDC_AUTOSAVE_DISABLEWHILEPLAYING, m_nDisableWhilePlaying);
	DDX_Check (pDX, IDC_AUTOSAVE_DISABLEWHILERECORDING, m_nDisableWhileRecording);
}

// ダイアログの初期化
BOOL CAutoSaveDlg::OnInitDialog () {
	BOOL bRet = CDialog::OnInitDialog ();
	((CSpinButtonCtrl*)GetDlgItem (IDC_AUTOSAVE_INTERVALSP))->SetRange (1, 120);
	UpdateInterval ();
	UpdateDisableWhilePlaying ();
	UpdateDisableWhileRecording ();
	SetIntervalRange ();
	return bRet;
}



//------------------------------------------------------------------------------
// メッセージマップ
//------------------------------------------------------------------------------
BEGIN_MESSAGE_MAP (CAutoSaveDlg, CDialog)
	ON_BN_CLICKED (IDC_AUTOSAVE_ON, OnChangeOn)
	ON_BN_CLICKED (IDC_AUTOSAVE_DELETEALLFILENOW, OnDeleteAllFileNow)	
END_MESSAGE_MAP ()

// 『自動保存をする(ドキュメントが変更されている場合のみ)』
void CAutoSaveDlg::OnChangeOn () {
	UpdateInterval ();
	UpdateDisableWhilePlaying ();
	UpdateDisableWhileRecording ();
}

// 『今すぐすべての自動保存ファイルを削除する』
void CAutoSaveDlg::OnDeleteAllFileNow () {
		
	// 本当にすべて削除してよいか確認
	long lRet = 0;
	CString strMsg;
	VERIFY (strMsg.LoadString (IDS_ARE_YOU_SURE_TO_DELETE_ALL_AUTOSAVEFILE_NOW_REALLY));
	lRet = AfxMessageBox (strMsg, MB_ICONQUESTION | MB_YESNOCANCEL);
	if (lRet != IDYES) {
		return;
	}
	
	// autosaveディレクトリ内の拡張子(*.skj)のファイルを全て削除する。
	lRet = 0;
	CString strFileName1;
	CString strFileName2;
	VERIFY (strFileName1.LoadString (IDS_AUTOSAVEFILENAME));
	strFileName2 = m_strExeFilePath + strFileName1;
	HANDLE hFind = NULL;
	WIN32_FIND_DATA fd;
	hFind = ::FindFirstFile ((LPCTSTR)strFileName2, &fd);
	if (hFind != INVALID_HANDLE_VALUE) {
		do {
			if (_tcscmp (fd.cFileName, _T(".")) != 0 &&
				_tcscmp (fd.cFileName, _T("..")) != 0) {
				CString strFileName3;
				CString strFileName4;
				VERIFY (strFileName3.LoadString (IDS_AUTOSAVEDIRNAME));
				strFileName4 = m_strExeFilePath + strFileName3 + fd.cFileName;
				BOOL bRet = _tremove (strFileName4);
				if (bRet == FALSE) {
					_RPTF1 (_CRT_WARN, "AutoSaveFile Delete Failed. - \"%s\"\n", strFileName4);				
				}
				else {
					_RPTF1 (_CRT_WARN, "AutoSaveFile Delete Successful. - \"%s\"\n", strFileName4);
				}
				lRet++;
			}
		} while (::FindNextFile (hFind, &fd));
		::FindClose (hFind);
	}
}