void TestDialog::OnButtonSelect( wxCommandEvent& event )
{
   //	wxMessageBox(wxT("impl"));
   	long  long total;
	long  long  free;
   	wxGetDiskSpace(wxT("/dev/sda"), (wxDiskspaceSize_t *) &total,(wxDiskspaceSize_t *) &free);
	
	//wxString msg(wxT("aaaa"));
	wxString msg;
	//msg.FromAscii("aaaaaaaaaaaaaaaa");
	//msg.Format(wxT("total is %l, free is %l , Usage: %f "), total, free,  (total-free)*100/total);
	//msg.Printf(wxT("total is %l, free is %l , Usage: %f "), total, free,  (total-free)*100/total);
	msg.Printf(wxT("total is %d, free is %d , Usage: %f "), 100 , 200,  (total-free)*100/total);
	//msg.Format(wxT(" i is %d\n"), 100);
	wxMessageBox(msg);	
}
///////////////
// Constructor
HDAudioProvider::HDAudioProvider(AudioProvider *source) {
	// Copy parameters
	bytes_per_sample = source->GetBytesPerSample();
	num_samples = source->GetNumSamples();
	channels = source->GetChannels();
	sample_rate = source->GetSampleRate();
	filename = source->GetFilename();

	// Check free space
	wxLongLong freespace;
	if (wxGetDiskSpace(DiskCachePath(), NULL, &freespace)) {
		if (num_samples * channels * bytes_per_sample > freespace) {
			throw wxString(_T("Not enough free diskspace in "))+DiskCachePath()+wxString(_T(" to cache the audio"));
		}
	}

	// Open output file
	diskCacheFilename = DiskCacheName();
	file_cache.Create(diskCacheFilename,true,wxS_DEFAULT);
	file_cache.Open(diskCacheFilename,wxFile::read_write);
	if (!file_cache.IsOpened()) throw _T("Unable to write to disk cache.");

	// Start progress
	volatile bool canceled = false;
	DialogProgress *progress = new DialogProgress(NULL,_T("Load audio"),&canceled,_T("Reading to Hard Disk cache"),0,num_samples);
	progress->Show();

	// Write to disk
	int block = 4096;
	char *temp = new char[block * channels * bytes_per_sample];
	for (__int64 i=0;i<num_samples && !canceled; i+=block) {
		if (block+i > num_samples) block = num_samples - i;
		source->GetAudio(temp,i,block);
		file_cache.Write(temp,block * channels * bytes_per_sample);
		progress->SetProgress(i,num_samples);
	}
	file_cache.Seek(0);

	// Finish
	if (!canceled) {
		progress->Destroy();
	}
	else {
		file_cache.Close();
		throw wxString(_T("Audio loading cancelled by user"));
	}
}
void DirectoriesPrefs::UpdateFreeSpace(wxCommandEvent & e)
{
   wxString tempDir;
   wxString label;

   if (mTempDir != NULL) {
      tempDir = mTempDir->GetValue();
   }

   if (wxDirExists(tempDir)) {
      wxLongLong space;
      wxGetDiskSpace(tempDir, NULL, &space);
      label = Internat::FormatSize(space);
   }
   else {
      label = _("unavailable - above location doesn't exist");
   }

   if( mFreeSpace != NULL ) {
      mFreeSpace->SetLabel(label);
   }
}
void DirectoriesPrefs::UpdateFreeSpace(wxCommandEvent & WXUNUSED(event))
{
   wxString tempDir;
   wxString label;

   if (mTempDir != NULL) {
      tempDir = mTempDir->GetValue();
   }

   if (wxDirExists(tempDir)) {
      wxLongLong space;
      wxGetDiskSpace(tempDir, NULL, &space);
      label = Internat::FormatSize(space);
   }
   else {
      label = _("unavailable - above location doesn't exist");
   }

   if( mFreeSpace != NULL ) {
      mFreeSpace->SetLabel(label);
      mFreeSpace->SetName(label); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
   }
}
Beispiel #5
0
void InteractiveInputTestCase::TestDiskInfo()
{
#ifdef TEST_INFO_FUNCTIONS
    wxPuts(wxT("*** Testing wxGetDiskSpace() ***"));

    for ( ;; )
    {
        wxChar pathname[128];
        wxPrintf(wxT("Enter a directory name (press ENTER or type 'quit' to escape): "));
        if ( !wxFgets(pathname, WXSIZEOF(pathname), stdin) )
            break;

        // kill the last '\n'
        pathname[wxStrlen(pathname) - 1] = 0;
        
        if (pathname[0] == '\0' || wxStrcmp(pathname, "quit") == 0)
            break;

        wxLongLong total, free;
        if ( !wxGetDiskSpace(pathname, &total, &free) )
        {
            wxPuts(wxT("ERROR: wxGetDiskSpace failed."));
        }
        else
        {
            wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"),
                    (total / 1024).ToString().c_str(),
                    (free / 1024).ToString().c_str(),
                    pathname);
        }
        
        wxPuts("\n");
    }

    wxPuts("\n");
#endif // TEST_INFO_FUNCTIONS
}
/*
What could be improved here:
-Option to prepend a numerical value to the destination filename to maintain 
the same order as the playlist
-Option to create a directory in the destination directory based on playlist name

SiW
*/
void MusikApp::CopyFiles(const MusikSongIdArray &songs)
{
	//--------------------------------//
	//--- first choose a directory ---//
	//--------------------------------//
	wxFileName destdir;
	wxDirDialog dirdlg( g_MusikFrame, _("Please choose location to copy songs to:"), wxT(""), wxDD_NEW_DIR_BUTTON );
	if ( dirdlg.ShowModal() == wxID_OK )
		destdir.AssignDir(dirdlg.GetPath());
	else
		return;
	wxLongLong llFree;
	wxGetDiskSpace(destdir.GetFullPath(),NULL,&llFree);
	wxLongLong llNeeded =  songs.GetTotalFileSize();
	if(llFree  < llNeeded)
	{
		wxLongLong_t  ToLessBytes = llNeeded.GetValue() - llFree.GetValue();
		wxString  sToLessBytes = wxString::Format(wxT("%")wxLongLongFmtSpec wxT("d"), ToLessBytes);
		// not enough free space
		wxString errmsg = wxString::Format(_("There is not enough free space in directory \"%s\". You need %s bytes more free. Continue nevertheless?"),(const wxChar *)destdir.GetFullPath(),(const wxChar *)sToLessBytes);
		if(wxMessageBox(errmsg,	_("File copy warning"),wxYES|wxNO|wxCENTER|wxICON_EXCLAMATION ) == wxNO)
		{
			return;
		}
	}


	//-----------------------------------------------------//
	//--- now just loop through the files and copy them ---//
	//-----------------------------------------------------//

	wxProgressDialog dialog(_T("Copy files dialog"),
		_T("An informative message"),
		100,    // range
		g_MusikFrame,   // parent
		wxPD_CAN_ABORT |
		wxPD_APP_MODAL |
		// wxPD_AUTO_HIDE | -- try this as well
		wxPD_ELAPSED_TIME |
		wxPD_ESTIMATED_TIME |
		wxPD_REMAINING_TIME);

	wxLongLong llRemaining = llNeeded;

	for ( size_t n = 0; n < songs.GetCount(); n++ )
	{
		const wxFileName & sourcename = songs[n].Song()->MetaData.Filename;
		wxFileName destname( sourcename );
		destname.SetPath(destdir.GetPath(0));   // GetPath(0) because the default is GetPath(int flags = wxPATH_GET_VOLUME,
		destname.SetVolume(destdir.GetVolume());	  // i do it this complicated way, because wxFileName::SetPath() is buggy, as it does not handle the volume of path
		wxLongLong llPercent = ((llNeeded - llRemaining) * wxLL(100) /llNeeded );
		
		if(!dialog.Update(llPercent.ToLong(),wxString::Format(_("copying %s"),(const wxChar *)sourcename.GetFullPath())))
		{
			break;
		}
		if(!wxCopyFile( sourcename.GetFullPath(), destname.GetFullPath()))
		{

			wxString errmsg = wxString::Format(_("Failed to copy file %s. Continue?"),(const wxChar *)sourcename.GetFullPath());
			if(wxMessageBox(errmsg,	_("File copy error"),wxYES|wxNO|wxCENTER|wxICON_ERROR ) == wxNO)
				break;
		}
		llRemaining -= songs[n].Song()->MetaData.nFilesize;
	}
	dialog.Update(99,wxT(""));	// this is needed to make the gauge fill the whole area.
	dialog.Update(100,wxT(""));

}