OSDN Git Service

This commit was manufactured by cvs2svn to create branch 'Bb62'.
[gikonavigoeson/gikonavi.git] / DefaultFileManager.pas
1 unit DefaultFileManager;
2
3 {!
4 \file       DefaultFileManager.pas
5 \brief      \8f\89\8aú\90Ý\92è\83t\83@\83C\83\8b\8aÇ\97\9d\83N\83\89\83X
6 }
7 interface
8
9 uses
10     Windows, Classes, Controls, ComCtrls, SysUtils;
11
12 type
13
14     TDefaultFileManager = class(TObject)
15     private
16         {!
17         \brief      \90â\91Î\83p\83X\82Å\95Ô\82·\81i\83C\83\93\83X\83g\81[\83\8b\83t\83H\83\8b\83_\89º)
18         \param      Path    \83C\83\93\83X\83g\81[\83\8b\83t\83H\83\8b\83_\82©\82ç\82Ì\91\8a\91Î\83p\83X
19         }
20         class function GetFilePath(const Path: String) : String;
21         {!
22         \brief          FromFile\82ª\91\8dÝ\82µ\81CToFile\82ª\91\8dÝ\82µ\82È\82¢\8fê\8d\87\82É\83R\83s\81[\82·\82é
23         \param          FromFile    \8f\89\8aú\90Ý\92è\83t\83@\83C\83\8b\94z\92u\8c³
24         \param      ToFile      \94z\92u\90æ
25         }
26         class procedure CopyFile(const FromFile: String; const ToFile : String);
27     public
28         {!
29         \brief          \8f\89\8aú\90Ý\92è\83t\83@\83C\83\8b\82ð\8ew\92è\88Ê\92u\82É\83R\83s\81[\82·\82é
30         \param          FileName    \8f\89\8aú\90Ý\92è\83t\83@\83C\83\8b\82Ì\94z\92u\8ew\92è\83t\83@\83C\83\8b
31         }
32         class procedure CopyDefaultFiles(const FileName: String);
33     end;
34
35 implementation
36
37 uses
38     IniFiles,ShellAPI, GikoSystem, MojuUtils;
39
40 class procedure TDefaultFileManager.CopyDefaultFiles(const FileName: String);
41 const
42     FROM_KEY    = 'FROM';
43     TO_KEY      = 'TO';
44 var
45     ini : TMemIniFile;
46     sections : TStringList;
47     i: Integer;
48 begin
49     if ( FileExists(FileName) ) then begin
50         ini := TMemIniFile.Create( FileName );
51         sections := TStringList.Create;
52         try
53             // \82·\82×\82Ä\82Ì\83Z\83N\83V\83\87\83\93\82ð\93Ç\82Ý\8d\9e\82Þ
54             ini.ReadSections(sections);
55             for i := 0 to sections.Count - 1 do begin
56                 // FROM \82©\82ç TO\82É\83t\83@\83C\83\8b\82ð\83R\83s\81[\82·\82é
57                 CopyFile( ini.ReadString(sections[i], FROM_KEY, ''),
58                              ini.ReadString(sections[i], TO_KEY, '') );
59             end;
60         finally
61             sections.Clear;
62             sections.Free;
63             ini.Free;
64         end;
65     end;
66
67 end;
68 class procedure TDefaultFileManager.CopyFile(
69     const FromFile: String; const ToFile : String);
70 var
71     fromPath, toPath : String;
72 begin
73     // \94z\92u\8c³\81C\94z\92u\90æ\82Ì\82Ç\82¿\82ç\82©\82ª\96¢\92è\82Ì\8fê\8d\87\82Í\89½\82à\82µ\82È\82¢
74     if ( (FromFile <> '') and (ToFile <> '') ) then begin
75         // ../ \82Æ\82©\82Å\83C\83\93\83X\83g\81[\83\8b\83t\83H\83\8b\83_\82æ\82è\8fã\82Ì\97Ì\88æ\82É\83A\83N\83Z\83X\82³\82ê\82é\82Æ
76         // \8d¢\82é\82Ì\82Å\92u\8a·\82µ\82Ä\82µ\82Ü\82¤
77         fromPath := GetFilePath( FromFile );
78         toPath := GetFilePath( ToFile );
79         if ( FileExists(fromPath) ) then begin
80             // \94z\92u\90æ\82É\82 \82Á\82½\82ç\89½\82à\82µ\82È\82¢
81             if (not FileExists(toPath)) then begin
82                 // \94z\92u\90æ\82Ì\83t\83H\83\8b\83_\82ð\90\90¬\82·\82é
83                 GikoSys.ForceDirectoriesEx(
84                     ExtractFilePath(toPath));
85                 Windows.CopyFile( PChar(fromPath), PChar(toPath), False);
86             end;
87         end;
88     end;
89
90 end;
91 class function TDefaultFileManager.GetFilePath(const Path: String): String;
92 begin
93     Result := GikoSys.GetAppDir +
94         CustomStringReplace(
95             CustomStringReplace(Path, '/', '\' ), '..\', '');
96 end;
97 end.