Ejemplo n.º 1
0
static bool ExtractFiles(lzma::SimpleArchive *archive)
{
    lzma::FileInfo *fi;
    char *uncompressed;

    FileTransaction trans;
    for (int i = 0; gPayloadData[i].fileName; i++) {
        if (!gPayloadData[i].install)
            continue;
        int idx = lzma::GetIdxFromName(archive, gPayloadData[i].fileName);
        if (-1 == idx) {
            NotifyFailed(_TR("Some files to be installed are damaged or missing"));
            return false;
        }

        fi = &archive->files[idx];
        uncompressed = lzma::GetFileDataByIdx(archive, idx, nullptr);
        if (!uncompressed) {
            NotifyFailed(_TR("The installer has been corrupted. Please download it again.\nSorry for the inconvenience!"));
            return false;
        }
        ScopedMem<WCHAR> filePath(str::conv::FromUtf8(fi->name));
        ScopedMem<WCHAR> extPath(path::Join(gGlobalData.installDir, filePath));
        bool ok = trans.WriteAll(extPath, uncompressed, fi->uncompressedSize);
        free(uncompressed);
        if (!ok) {
            ScopedMem<WCHAR> msg(str::Format(_TR("Couldn't write %s to disk"), filePath));
            NotifyFailed(msg);
            return false;
        }
        trans.SetModificationTime(extPath, fi->ftModified);

        ProgressStep();
    }

    return trans.Commit();
}
Ejemplo n.º 2
0
static bool InstallCopyFiles()
{
    // extract all payload files one by one (transacted, if possible)
    ZipFile archive(GetOwnPath());
    FileTransaction trans;

    for (int i = 0; gPayloadData[i].filepath; i++) {
        // skip files that are only uninstalled
        if (!gPayloadData[i].install)
            continue;
        ScopedMem<WCHAR> filepathT(str::conv::FromUtf8(gPayloadData[i].filepath));

        size_t size;
        ScopedMem<char> data(archive.GetFileData(filepathT, &size));
        if (!data) {
            NotifyFailed(L"Some files to be installed are damaged or missing");
            return false;
        }

        ScopedMem<WCHAR> extpath(path::Join(gGlobalData.installDir, path::GetBaseName(filepathT)));
        bool ok = trans.WriteAll(extpath, data, size);
        if (!ok) {
            ScopedMem<WCHAR> msg(str::Format(L"Couldn't write %s to disk", filepathT));
            NotifyFailed(msg);
            return false;
        }

        // set modification time to original value
        FILETIME ftModified = archive.GetFileTime(filepathT);
        trans.SetModificationTime(extpath, ftModified);

        ProgressStep();
    }

    return trans.Commit();
}