Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. void UpdateSound()
  2. {
  3.     ToggleButtons( false );
  4.     g_sndUpdate->EnableWindow( false );
  5.     g_launcherDir = boost::filesystem::current_path();
  6.     g_pStatus->SetWindowTextW( L"Status: Downloading" );
  7.     boost::filesystem::path location;
  8.  
  9.     location = g_launcherDir.wstring() + L"\\" + g_soundPackLanguageW + L".zip";
  10.  
  11.     if ( boost::filesystem::exists( location ) )
  12.         boost::filesystem::remove( location );
  13.  
  14.     debug_log( "%s %S", g_soundPackLanguage, g_soundPackLanguageW );
  15.     if ( strstr( g_soundPackLanguage, "English" ) )
  16.     {
  17.  
  18.         downloadFile( SoundURL_EN, location.wstring().c_str() );
  19.         debug_log( "JP%S", SoundURL_EN );
  20.     }
  21.     else
  22.     {
  23.         downloadFile( SoundURL_JP, location.wstring().c_str() );
  24.         debug_log( "JP%S", SoundURL_JP );
  25.     }
  26.  
  27.     HZIP hz = OpenZip( location.wstring().c_str(), 0 );
  28.     debug_log( "Unzipping:%S", location.wstring().c_str() );
  29.     g_pStatus->SetWindowTextW( L"Status: Extracting" );
  30.     ZIPENTRY ze; GetZipItem( hz, -1, &ze ); int numitems = ze.index;
  31.     // -1 gives overall information about the zipfile
  32.     for ( int zi = 0; zi < numitems; zi++ )
  33.     {
  34.         ZIPENTRY ze; GetZipItem( hz, zi, &ze ); // fetch individual details
  35.         UnzipItem( hz, zi, ze.name );         // e.g. the item's name.
  36.  
  37.     }
  38.     CloseZip( hz );
  39.  
  40.     if ( boost::filesystem::exists( location ) )
  41.         boost::filesystem::remove( location );
  42.     if ( boost::filesystem::exists( g_launcherDir.wstring() + L"\\Sound Pack\\" + g_soundPackLanguageW + L"\\" ) )
  43.         boost::filesystem::remove_all( g_launcherDir.wstring() + L"\\Sound Pack\\" + g_soundPackLanguageW + L"\\" );
  44.     if ( !boost::filesystem::exists( g_launcherDir.wstring() + L"\\Sound Pack\\" + g_soundPackLanguageW + L"\\" ) )
  45.         boost::filesystem::create_directory( g_launcherDir.wstring() + L"\\Sound Pack\\" + g_soundPackLanguageW + L"\\" );
  46.  
  47.     location = g_launcherDir.wstring() + L"\\" + g_soundPackLanguageW + L"\\";
  48.  
  49.     int idx = 0;
  50.     int maxCount = dirCount( location );
  51.     debug_line;
  52.     g_pProgressBar->SetRange( 0, 420 );
  53.  
  54.     debug_line;
  55.     boost::filesystem::directory_iterator end_itr;
  56.     for ( boost::filesystem::directory_iterator itr( location ); itr != end_itr; ++itr )
  57.     {
  58.         debug_line;
  59.         if ( !is_directory( itr->status() ) )
  60.         {
  61.             string currentFileName = itr->path().filename().string();
  62.             debug_log( "%s", currentFileName.c_str() );
  63.             if ( boost::filesystem::exists( location.string() + currentFileName ) )
  64.             {
  65.                 wchar_t temp[ 256 ];
  66.                 wsprintf( temp, L"Status: Moving(%d/%d)", idx, maxCount );
  67.                 g_pStatus->SetWindowTextW( temp );
  68.                 g_pProgressBar->SetPos( idx );
  69.                 idx++;
  70.                 boost::filesystem::copy( location.string() + currentFileName, g_launcherDir.string() + "\\Sound Pack\\" + g_soundPackLanguage + "\\" + currentFileName );
  71.             }
  72.         }
  73.     }
  74.  
  75.     boost::filesystem::remove_all( location );
  76.     g_pStatus->SetWindowTextW( L"Status: Idle" );
  77.     ToggleButtons( true );
  78.     CheckButtonState();
  79.     g_pProgressBar->SetPos( 0 );
  80.    
  81.     if ( strstr( g_soundPackLanguage, "English" ) )
  82.     {
  83.         g_localSndDateEN = g_sndDateEN;
  84.         g_Config->Writer->SaveInt( "English Sound Date", g_sndDateEN );
  85.     }
  86.     else
  87.     {
  88.         g_localSndDateJP = g_sndDateJP;
  89.         g_Config->Writer->SaveInt( "Japanese Sound Date", g_sndDateJP );
  90.     }
  91.  
  92.     ExitThread( 0 );
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement