| 1 |
unit NIcoVitanD_setting; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 |
Dialogs, IniFiles, StdCtrls, ExtCtrls, |
| 8 |
ShlObj, |
| 9 |
Filectrl, |
| 10 |
RegularExpressions; |
| 11 |
|
| 12 |
type |
| 13 |
TSettingForm = class(TForm) |
| 14 |
CommentLogLE: TLabeledEdit; |
| 15 |
GroupBox1: TGroupBox; |
| 16 |
SettingFileLE: TLabeledEdit; |
| 17 |
CommentLogDefaultBtn: TButton; |
| 18 |
SettingFilesDefaultBtn: TButton; |
| 19 |
OpenDialog1: TOpenDialog; |
| 20 |
procedure FormDblClick(Sender: TObject); |
| 21 |
procedure FormClick(Sender: TObject); |
| 22 |
procedure CommentLogDefaultBtnClick(Sender: TObject); |
| 23 |
function GetSpecialFolder(CSIDL: Integer): String; |
| 24 |
procedure FormCreate(Sender: TObject); |
| 25 |
procedure SettingFilesDefaultBtnClick(Sender: TObject); |
| 26 |
procedure FormDestroy(Sender: TObject); |
| 27 |
procedure CommentLogLEClick(Sender: TObject); |
| 28 |
function SaveFolderValidate(SFvalidate:String):String; |
| 29 |
function IsWritableFolder(aPath: string): Boolean; |
| 30 |
private |
| 31 |
{ Private éž } |
| 32 |
public |
| 33 |
{ Public éž } |
| 34 |
end; |
| 35 |
|
| 36 |
const |
| 37 |
AppliName = 'NicoVitanD'; |
| 38 |
MakerName = 'arigayas'; |
| 39 |
|
| 40 |
var |
| 41 |
SettingForm: TSettingForm; |
| 42 |
FilePath: string; |
| 43 |
SettingFilePath , CommentLogPath: string; |
| 44 |
|
| 45 |
implementation |
| 46 |
|
| 47 |
{$R *.dfm} |
| 48 |
|
| 49 |
procedure TSettingForm.CommentLogDefaultBtnClick(Sender: TObject); |
| 50 |
begin |
| 51 |
CommentLogLE.Text := GetSpecialFolder(CSIDL_APPDATA) + '\' +MakerName + '\' + AppliName + '\CommentLog'; |
| 52 |
end; |
| 53 |
|
| 54 |
procedure TSettingForm.CommentLogLEClick(Sender: TObject); |
| 55 |
var |
| 56 |
SelectFolder :string; //tH_ĚpXđi[ˇéĎ |
| 57 |
SelectFolderResult :string; |
| 58 |
SpDir :string; |
| 59 |
begin |
| 60 |
// SpDir := '::' + GUIDToString(CLSID_MyComputer); // }CRs
[^đJAShlObj K{ |
| 61 |
if SelectDirectory('RenĆRgđŰśˇétH_ĚIđ',SpDir,SelectFolder) then |
| 62 |
SelectFolderResult := SaveFolderValidate(SelectFolder); |
| 63 |
if SelectFolderResult = 'OK' then |
| 64 |
begin |
| 65 |
CommentLogLE.Text := SelectFolder + '\CommentLog\'; |
| 66 |
CommentLogPath := SelectFolder + '\CommentLog\'; |
| 67 |
|
| 68 |
SettingFileLE.Text := SelectFolder; |
| 69 |
SettingFilePath := SelectFolder; |
| 70 |
ShowMessage(SelectFolder); |
| 71 |
end |
| 72 |
else |
| 73 |
begin |
| 74 |
if not(SelectFolderResult = '') then |
| 75 |
MessageDlg( SelectFolderResult , mtInformation, [mbOk], 0); // G[ |
| 76 |
end; |
| 77 |
end; |
| 78 |
|
| 79 |
procedure TSettingForm.FormClick(Sender: TObject); |
| 80 |
begin |
| 81 |
SettingForm.Caption:='_uNbNĹœܡ'; |
| 82 |
// GroupBox1.Enabled := not GroupBox1.Enabled; |
| 83 |
end; |
| 84 |
|
| 85 |
procedure TSettingForm.FormCreate(Sender: TObject); |
| 86 |
var |
| 87 |
Ini : TIniFile; |
| 88 |
begin |
| 89 |
Ini := TInifile.Create(ChangeFileExt( Application.ExeName, '.ini')); //init@CĚśÝđ`FbNˇé |
| 90 |
// AppliName := ExtractFileName( ChangeFileExt( Application.ExeName, '')); |
| 91 |
|
| 92 |
try |
| 93 |
SettingFilePath := Ini.ReadString('Path', 'SettingFile', SettingFilePath); |
| 94 |
CommentLogPath := Ini.ReadString('Path', 'CommentLog', CommentLogPath); |
| 95 |
finally |
| 96 |
Ini.Free; |
| 97 |
end; |
| 98 |
|
| 99 |
// [U[˛ĆÉA[~O (ÚŽ) ˇéę |
| 100 |
// [user profile]\Application data |
| 101 |
FilePath := GetSpecialFolder(CSIDL_APPDATA) + '\' + MakerName + '\' + AppliName; |
| 102 |
|
| 103 |
if SettingFilePath ='' then |
| 104 |
begin |
| 105 |
SettingFileLE.Text := FilePath; |
| 106 |
end |
| 107 |
else |
| 108 |
begin |
| 109 |
SettingFileLE.Text := SettingFilePath; |
| 110 |
end; |
| 111 |
|
| 112 |
if CommentLogPath ='' then |
| 113 |
begin |
| 114 |
CommentLogLE.Text := FilePath + '\CommentLog\'; |
| 115 |
end |
| 116 |
else |
| 117 |
CommentLogLE.Text := CommentLogPath; |
| 118 |
|
| 119 |
end; |
| 120 |
|
| 121 |
procedure TSettingForm.FormDblClick(Sender: TObject); |
| 122 |
begin |
| 123 |
Close; |
| 124 |
end; |
| 125 |
|
| 126 |
procedure TSettingForm.FormDestroy(Sender: TObject); |
| 127 |
var |
| 128 |
Ini : TIniFile; |
| 129 |
begin |
| 130 |
// wčtH_ŞśÝľÄ˘éŠmF |
| 131 |
// tH_pXđĎÉi[ |
| 132 |
SettingFilePath := SettingFileLE.Text; |
| 133 |
|
| 134 |
CommentLogPath := CommentLogLE.Text; |
| 135 |
|
| 136 |
//@NicoVitanD Ě{ĚĚĘuđinit@CÉL^ |
| 137 |
Ini := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini')); |
| 138 |
|
| 139 |
try |
| 140 |
Ini.WriteString('Path', 'CommentLog', CommentLogPath); |
| 141 |
Ini.WriteString('Path', 'SettingFile', SettingFilePath); |
| 142 |
finally |
| 143 |
Ini.Free; |
| 144 |
end; |
| 145 |
end; |
| 146 |
|
| 147 |
// http://shusakuorz.wordpress.com/2011/08/05/pXĚćžapplication-dataŇ/ |
| 148 |
function TSettingForm.GetSpecialFolder(CSIDL: Integer): String; |
| 149 |
var |
| 150 |
Path: array[0..MAX_PATH] of Char; |
| 151 |
Pidl: PItemIDList; |
| 152 |
begin |
| 153 |
SHGetSpecialFolderLocation(Application.Handle, CSIDL, Pidl); |
| 154 |
SHGetPathFromIDList(Pidl, Path); |
| 155 |
Result := Path; |
| 156 |
end; |
| 157 |
|
| 158 |
|
| 159 |
function TSettingForm.SaveFolderValidate(SFvalidate: String): String; |
| 160 |
var |
| 161 |
DriveName,DriveType : string; |
| 162 |
Avail, Total, Free: Int64; |
| 163 |
r: Byte; |
| 164 |
const |
| 165 |
Limit = 100000000; // 100MB |
| 166 |
begin |
| 167 |
if TRegEx.IsMatch(SFvalidate, '^file:') then |
| 168 |
begin |
| 169 |
Result:='tH_[ÉÍ "file:" ĹnÜétH_[đÝčoÜšńI'; |
| 170 |
end |
| 171 |
else |
| 172 |
DriveName := ExtractFileDrive(SFvalidate); |
| 173 |
// óŤeĘ`FbN |
| 174 |
GetDiskFreeSpaceEx( PWideChar( WideString(DriveName) ), Avail, Total, @Free ); |
| 175 |
if Avail < Limit then |
| 176 |
Result:='óŤeĘŞŤčÜšńBNeed: 100MB' |
| 177 |
else |
| 178 |
// { DONE : őwhCuđÖ~ˇé } |
| 179 |
begin |
| 180 |
r := GetDriveType(PChar(DriveName)); |
| 181 |
case r of |
| 182 |
DRIVE_NO_ROOT_DIR: DriveType := 'No Root'; // No Root |
| 183 |
DRIVE_REMOVABLE: DriveType := 'Removable'; // veXg |
| 184 |
DRIVE_FIXED: DriveType := 'HDD'; |
| 185 |
DRIVE_REMOTE: DriveType := 'Network'; |
| 186 |
DRIVE_CDROM: DriveType := 'őwhCuÍŔSĚ˝ßŰśtH_ĆľÄgŚÜšńB'; |
| 187 |
DRIVE_RAMDISK: DriveType := 'RamDisk'; |
| 188 |
else DriveType := 'hCuĚíŢđťĘĹŤÜšńĹľ˝BŔSĚ˝ßŰśtH_ĆľÄgŚÜšńB'; // Unknown |
| 189 |
end; |
| 190 |
if (r = 3) or (r = 4) or (r = 6) then |
| 191 |
// ŤÝtH_ŠÂ\Š`FbN |
| 192 |
if IsWritableFolder(SFvalidate) = false then |
| 193 |
Result:='t@CđۜōȢtH_šBÄxtH_đIńĹžł˘B' |
| 194 |
else |
| 195 |
Result:='OK' |
| 196 |
else |
| 197 |
Result := DriveType; |
| 198 |
end; |
| 199 |
end; |
| 200 |
|
| 201 |
// Thanks Mr.DEKO |
| 202 |
// http://hpcgi1.nifty.com/MADIA/DelphiBBS/wwwlng.cgi?print+201303/13030017.txt |
| 203 |
function TSettingForm.IsWritableFolder(aPath: string): Boolean; |
| 204 |
var |
| 205 |
hFile: THandle; |
| 206 |
dFileName: String; |
| 207 |
begin |
| 208 |
result := False; |
| 209 |
if not SysUtils.DirectoryExists(aPath) then |
| 210 |
Exit; |
| 211 |
dFileName := IncludeTrailingPathDelimiter(aPath) + 'writablecheck.temporary'; |
| 212 |
UniqueString(dFileName); |
| 213 |
hFile := CreateFile(PChar(dFileName), GENERIC_WRITE, 0, nil, CREATE_ALWAYS, |
| 214 |
FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE, 0); |
| 215 |
result := (hFile <> INVALID_HANDLE_VALUE); |
| 216 |
if result then |
| 217 |
CloseHandle(hFile); |
| 218 |
end; |
| 219 |
|
| 220 |
|
| 221 |
procedure TSettingForm.SettingFilesDefaultBtnClick(Sender: TObject); |
| 222 |
begin |
| 223 |
SettingFileLE.Text := GetSpecialFolder(CSIDL_APPDATA) + '\' + MakerName + '\' + AppliName ; |
| 224 |
end; |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
end. |