French translation update by Mustapha Senhaji.
[Rockbox.git] / rbutil / installlog.cpp
blobe9dad794cb14301d1b5bbaaaa22fd9635394de43
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * Module: rbutil
9 * File: installlog.cpp
11 * Copyright (C) 2006 Christi Alice Scarborough
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
21 #include "installlog.h"
22 #include "rbutil.h"
24 InstallLog::InstallLog(wxString logname, bool CreateLog)
26 wxString buf;
27 dirtyflag = true;
29 if (! CreateLog && ! wxFileExists(logname) ) return;
31 logfile = new wxFileConfig(wxEmptyString, wxEmptyString, logname);
34 if (!logfile)
36 buf.Printf(_("Failed to create install log file: %s"), logname.c_str());
37 wxLogWarning(buf);
38 return;
41 logfile->SetPath("/InstallLog");
42 if (logfile->Exists("Version") &&
43 logfile->Read("Version", 0l) != LOGFILE_VERSION )
45 buf.Printf(_("Logfile version mismatch: %s"), logname.c_str() );
46 wxLogWarning(buf);
47 delete logfile;
48 return;
51 logfile->Write("Version", LOGFILE_VERSION);
52 dirtyflag = false;
55 InstallLog::~InstallLog()
57 if (dirtyflag) return;
59 delete logfile;
62 unsigned int InstallLog::WriteFile(wxString filepath, bool isDir)
64 wxString key, buf;
65 long installcount = 0;
67 if (dirtyflag) return true;
69 filepath.Replace(PATH_SEP, wxT("/") );
71 if (filepath.GetChar(0) == '/')
72 filepath = filepath.Right(filepath.Len() - 1);
74 logfile->SetPath(wxT("/FilePaths"));
75 installcount = logfile->Read(filepath, 0l);
77 if (isDir)
79 filepath.Append(wxT("/" DIRECTORY_KLUDGE) ); // Needed for empty dirs
82 logfile->Write(filepath, ++installcount);
84 return false;
87 unsigned int InstallLog::WriteFile(wxArrayString filepaths)
89 unsigned long i;
90 unsigned int finalrc = false;
91 wxString thisone;
93 if (dirtyflag) return true;
95 for (i = 0; i < filepaths.GetCount(); i++);
97 if ( WriteFile(filepaths[i]) )
99 finalrc++;
103 return finalrc;
106 wxArrayString* InstallLog::GetInstalledFiles()
108 wxString curdir = "";
110 if (dirtyflag) return NULL;
111 workingAS.Clear();
113 EnumerateCurDir("");
115 wxArrayString* out = new wxArrayString(workingAS);
116 return out;
119 void InstallLog::EnumerateCurDir(wxString curdir)
121 bool contflag;
122 wxString curname, buf, buf2, pathcache;
123 long dummy;
125 buf.Printf(wxT("/FilePaths/%s"), curdir.c_str());
126 pathcache = logfile->GetPath();
127 logfile->SetPath(buf);
129 contflag = logfile->GetFirstGroup(curname, dummy);
130 while (contflag)
132 buf.Printf("%s/%s", curdir.c_str(), curname.c_str() );
133 buf2 = buf; buf2.Replace(wxT("/"), wxT(PATH_SEP));
134 workingAS.Add(buf2);
135 EnumerateCurDir(buf);
136 contflag = logfile->GetNextGroup(curname, dummy);
139 contflag = logfile->GetFirstEntry(curname, dummy);
140 while (contflag)
142 if (curname != wxT(DIRECTORY_KLUDGE) )
144 buf.Printf("%s/%s", curdir.c_str(), curname.c_str() );
145 buf2 = buf; buf2.Replace(wxT("/"), wxT(PATH_SEP));
146 workingAS.Add(buf2);
148 contflag = logfile->GetNextEntry(curname, dummy);
151 logfile->SetPath(pathcache);