/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/ramdump-lateset/pcsx2/ZipTools/thread_gzip.cpp
ViewVC logotype

Contents of /branch/debug/0.X/0.9.X/0.9.7/ramdump-lateset/pcsx2/ZipTools/thread_gzip.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 330 - (show annotations) (download)
Tue Dec 28 04:24:23 2010 UTC (9 years, 9 months ago) by william
File size: 2877 byte(s)
merged upstream r4154-r4160
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of te License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17
18 #include "App.h"
19 #include "SaveState.h"
20 #include "ThreadedZipTools.h"
21 #include "Utilities/SafeArray.inl"
22 #include "wx/wfstream.h"
23
24
25 BaseCompressThread::~BaseCompressThread() throw()
26 {
27 _parent::Cancel();
28 if( m_PendingSaveFlag )
29 {
30 wxGetApp().ClearPendingSave();
31 m_PendingSaveFlag = false;
32 }
33 }
34
35 void BaseCompressThread::SetPendingSave()
36 {
37 wxGetApp().StartPendingSave();
38 m_PendingSaveFlag = true;
39 }
40
41 void BaseCompressThread::ExecuteTaskInThread()
42 {
43 // TODO : Add an API to PersistentThread for this! :) --air
44 //SetThreadPriority( THREAD_PRIORITY_BELOW_NORMAL );
45
46 // Notes:
47 // * Safeguard against corruption by writing to a temp file, and then copying the final
48 // result over the original.
49
50 if( !m_src_list ) return;
51 SetPendingSave();
52
53 Yield( 3 );
54
55 uint listlen = m_src_list->GetLength();
56 for( uint i=0; i<listlen; ++i )
57 {
58 const ArchiveEntry& entry = (*m_src_list)[i];
59 if (!entry.GetDataSize()) continue;
60
61 wxArchiveOutputStream& woot = *(wxArchiveOutputStream*)m_gzfp->GetWxStreamBase();
62 woot.PutNextEntry( entry.GetFilename() );
63
64 static const uint BlockSize = 0x64000;
65 uint curidx = 0;
66
67 do {
68 uint thisBlockSize = std::min( BlockSize, entry.GetDataSize() - curidx );
69 m_gzfp->Write(m_src_list->GetPtr( entry.GetDataIndex() + curidx ), thisBlockSize);
70 curidx += thisBlockSize;
71 Yield( 2 );
72 } while( curidx < entry.GetDataSize() );
73
74 woot.CloseEntry();
75 }
76
77 m_gzfp->Close();
78
79 if( !wxRenameFile( m_gzfp->GetStreamName(), m_final_filename, true ) )
80 throw Exception::BadStream( m_final_filename )
81 .SetDiagMsg(L"Failed to move or copy the temporary archive to the destination filename.")
82 .SetUserMsg(_("The savestate was not properly saved. The temporary file was created successfully but could not be moved to its final resting place."));
83
84 Console.WriteLn( "(gzipThread) Data saved to disk without error." );
85 }
86
87 void BaseCompressThread::OnCleanupInThread()
88 {
89 _parent::OnCleanupInThread();
90 wxGetApp().DeleteThread( this );
91
92 safe_delete(m_gzfp);
93 safe_delete(m_src_list);
94 }
95

  ViewVC Help
Powered by ViewVC 1.1.22