foobar2000 SDK  2015-08-03
Public Member Functions | Private Attributes
winLocalFileScope

#include <win32_misc.h>

Public Member Functions

 winLocalFileScope ()
 
 winLocalFileScope (const char *inPath, file::ptr inReader, abort_callback &aborter)
 
 ~winLocalFileScope ()
 
void close ()
 
void open (const char *inPath, file::ptr inReader, abort_callback &aborter)
 
const wchar_t * Path () const
 

Private Attributes

bool m_isTemp
 
std::wstring m_path
 

Detailed Description

Definition at line 330 of file win32_misc.h.

Constructor & Destructor Documentation

winLocalFileScope::winLocalFileScope ( )
inline

Definition at line 335 of file win32_misc.h.

335 : m_isTemp() {}
winLocalFileScope::winLocalFileScope ( const char *  inPath,
file::ptr  inReader,
abort_callback aborter 
)
inline

Definition at line 336 of file win32_misc.h.

336  : m_isTemp() {
337  open( inPath, inReader, aborter );
338  }
void open(const char *inPath, file::ptr inReader, abort_callback &aborter)
Definition: win32_misc.cpp:180
winLocalFileScope::~winLocalFileScope ( )
inline

Definition at line 340 of file win32_misc.h.

340  {
341  close();
342  }

Member Function Documentation

void winLocalFileScope::close ( )

Definition at line 207 of file win32_misc.cpp.

207  {
208  if (m_isTemp && m_path.length() > 0) {
209  pfc::lores_timer timer;
210  timer.start();
211  for(;;) {
212  if (DeleteFile( m_path.c_str() )) break;
213  if (timer.query() > 1.0) break;
214  Sleep(10);
215  }
216  }
217  m_path.clear();
218 }
void start()
Definition: timers.h:93
std::wstring m_path
Definition: win32_misc.h:347
double query() const
Definition: timers.h:97
void winLocalFileScope::open ( const char *  inPath,
file::ptr  inReader,
abort_callback aborter 
)

Definition at line 180 of file win32_misc.cpp.

180  {
181  close();
182  if (inPath != NULL) {
183  if (_extract_native_path_ptr( inPath ) ) {
184  pfc::string8 prefixed;
185  pfc::winPrefixPath( prefixed, inPath );
187  m_isTemp = false;
188  return;
189  }
190  }
191 
192  pfc::string8 tempPath;
193  if (!uGetTempPath( tempPath )) uBugCheck();
194  tempPath.add_filename( PFC_string_formatter() << pfc::print_guid( pfc::createGUID() ) << ".rar" );
195 
197 
198  if (inReader.is_empty()) {
199  if (inPath == NULL) uBugCheck();
200  inReader = fileOpenReadExisting( inPath, aborter, 1.0 );
201  }
202 
203  file::ptr writer = fileOpenWriteNew( PFC_string_formatter() << "file://" << tempPath, aborter, 1.0 );
204  file::g_transfer_file( inReader , writer, aborter );
205  m_isTemp = true;
206 }
GUID createGUID()
Definition: guid.cpp:161
std::wstring m_path
Definition: win32_misc.h:347
bool _extract_native_path_ptr(const char *&p_fspath)
Definition: filesystem.cpp:942
string_wide_from_utf8_t string_wide_from_utf8
Definition: string_conv.h:160
void winPrefixPath(pfc::string_base &out, const char *p_path)
Definition: win-objects.cpp:55
file_ptr fileOpenWriteNew(const char *p_path, abort_callback &p_abort, double p_timeout=0)
Definition: filesystem.h:586
file_ptr fileOpenReadExisting(const char *p_path, abort_callback &p_abort, double p_timeout=0)
Definition: filesystem.h:580
PFC_NORETURN void SHARED_EXPORT uBugCheck()
BOOL SHARED_EXPORT uGetTempPath(pfc::string_base &out)
void add_filename(const char *fn)
Definition: string_base.h:257
const wchar_t* winLocalFileScope::Path ( ) const
inline

Definition at line 344 of file win32_misc.h.

344 {return m_path.c_str();}
std::wstring m_path
Definition: win32_misc.h:347

Field Documentation

bool winLocalFileScope::m_isTemp
private

Definition at line 346 of file win32_misc.h.

std::wstring winLocalFileScope::m_path
private

Definition at line 347 of file win32_misc.h.


The documentation for this class was generated from the following files: