2008-09-13 16:24:43 +00:00
#region Disclaimer / License
// Copyright (C) 2008, Kenneth Skovhede
// http://www.hexad.dk, opensource@hexad.dk
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Drawing ;
using System.Data ;
using System.Text ;
using System.Windows.Forms ;
using System.Windows.Forms.Wizard ;
2009-01-31 17:23:59 +00:00
using Duplicati.Datamodel ;
2008-09-13 16:24:43 +00:00
2008-09-13 16:32:45 +00:00
namespace Duplicati.GUI.Wizard_pages.Backends.File
2008-09-13 16:24:43 +00:00
{
2009-01-31 17:23:59 +00:00
public partial class FileOptions : WizardControl
2008-09-13 16:24:43 +00:00
{
2009-02-04 22:18:13 +00:00
FileSettings m_wrapper ;
2008-09-13 16:24:43 +00:00
private bool m_isUpdating = false ;
public FileOptions ()
2009-01-31 17:23:59 +00:00
: base ( "Backup storage options" , "On this page you can select where to store the backup data." )
2008-09-13 16:24:43 +00:00
{
InitializeComponent ();
2009-01-31 17:23:59 +00:00
base . PageEnter += new PageChangeHandler ( FileOptions_PageEnter );
base . PageLeave += new PageChangeHandler ( FileOptions_PageLeave );
2008-09-13 16:24:43 +00:00
}
2009-01-31 17:23:59 +00:00
void FileOptions_PageLeave ( object sender , PageChangedArgs args )
2008-09-13 16:24:43 +00:00
{
2009-01-31 17:23:59 +00:00
if ( args . Direction == PageChangedDirection . Back )
return ;
2008-09-13 16:24:43 +00:00
string targetpath ;
if ( UsePath . Checked )
targetpath = TargetFolder . Text ;
else
targetpath = TargetDrive . Text + "\\" + Folder . Text ;
2009-01-15 19:42:14 +00:00
if ( UseCredentials . Checked )
if (! Duplicati . Library . Backend . File . PreAuthenticate ( targetpath , Username . Text , Password . Text ))
{
MessageBox . Show ( this , "Failed to authenticate using the given credentials." , Application . ProductName , MessageBoxButtons . OK , MessageBoxIcon . Error );
return ;
}
2008-09-13 16:24:43 +00:00
try
{
if ( targetpath . Trim (). Length == 0 )
{
MessageBox . Show ( this , "You must enter a folder to backup to" , Application . ProductName , MessageBoxButtons . OK , MessageBoxIcon . Information );
2009-01-31 17:23:59 +00:00
args . Cancel = true ;
2008-09-13 16:24:43 +00:00
return ;
}
2009-01-31 17:23:59 +00:00
if (! System . IO . Path . IsPathRooted ( targetpath ))
2008-09-13 16:24:43 +00:00
{
MessageBox . Show ( this , "You must enter the full path of the folder" , Application . ProductName , MessageBoxButtons . OK , MessageBoxIcon . Information );
2009-01-31 17:23:59 +00:00
args . Cancel = true ;
2008-09-13 16:24:43 +00:00
return ;
}
if (! System . IO . Directory . Exists ( targetpath ))
{
switch ( MessageBox . Show ( this , "The selected folder does not exist. Do you want to create it?" , Application . ProductName , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question ))
{
case DialogResult . Yes :
System . IO . Directory . CreateDirectory ( targetpath );
break ;
case DialogResult . Cancel :
2009-01-31 17:23:59 +00:00
args . Cancel = true ;
2008-09-13 16:24:43 +00:00
return ;
}
}
}
catch ( Exception ex )
{
MessageBox . Show ( this , "An error occured while verifying the destination. Please make sure it exists and is accessible.\nError message: " + ex . Message , Application . ProductName , MessageBoxButtons . OK , MessageBoxIcon . Error );
2009-01-31 17:23:59 +00:00
args . Cancel = true ;
2008-09-13 16:24:43 +00:00
return ;
}
try
{
2009-02-04 22:47:29 +00:00
if ( System . IO . Directory . GetFileSystemEntries ( targetpath ). Length > 0 && new WizardSettingsWrapper ( m_settings ). PrimayAction == WizardSettingsWrapper . MainAction . Add )
2008-09-13 16:24:43 +00:00
if ( MessageBox . Show ( this , "The selected folder is not empty. Do you want to use it anyway?" , Application . ProductName , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Warning ) != DialogResult . Yes )
{
2009-01-31 17:23:59 +00:00
args . Cancel = true ;
2008-09-13 16:24:43 +00:00
return ;
}
}
catch ( Exception ex )
{
MessageBox . Show ( this , "An error occured while verifying the destination. Please make sure it exists and is accessible.\nError message: " + ex . Message , Application . ProductName , MessageBoxButtons . OK , MessageBoxIcon . Error );
2009-01-31 17:23:59 +00:00
args . Cancel = true ;
2008-09-13 16:24:43 +00:00
return ;
}
2009-02-04 22:18:13 +00:00
m_wrapper . Path = TargetFolder . Text ;
2008-09-13 16:24:43 +00:00
if ( UseCredentials . Checked )
{
2009-02-04 22:18:13 +00:00
m_wrapper . Username = Username . Text ;
m_wrapper . Password = Password . Text ;
2008-09-13 16:24:43 +00:00
}
else
{
2009-02-04 22:18:13 +00:00
m_wrapper . Username = m_wrapper . Password = "" ;
2008-09-13 16:24:43 +00:00
}
2009-02-04 22:18:13 +00:00
args . NextPage = new Add_backup . AdvancedOptions ();
2008-09-13 16:24:43 +00:00
}
2009-01-31 17:23:59 +00:00
private void RescanDrives ()
{
TargetDrive . Items . Clear ();
for ( char i = 'A' ; i < 'Z' ; i ++)
{
System . IO . DriveInfo di = new System . IO . DriveInfo ( i . ToString ());
if ( di . DriveType == System . IO . DriveType . Removable )
TargetDrive . Items . Add ( i . ToString () + ":" );
}
}
void FileOptions_PageEnter ( object sender , PageChangedArgs args )
{
2009-02-04 22:18:13 +00:00
m_wrapper = new WizardSettingsWrapper ( m_settings ). FileSettings ;
2009-01-31 17:23:59 +00:00
RescanDrives ();
2009-02-04 22:18:13 +00:00
if (! m_valuesAutoLoaded )
2009-01-31 17:23:59 +00:00
{
2009-02-04 22:18:13 +00:00
UsePath . Checked = true ;
TargetFolder . Text = m_wrapper . Path ;
2009-01-31 17:23:59 +00:00
2009-02-04 22:18:13 +00:00
UseCredentials . Checked = ! string . IsNullOrEmpty ( m_wrapper . Username );
Username . Text = m_wrapper . Username ;
Password . Text = m_wrapper . Password ;
2009-01-31 17:23:59 +00:00
}
}
2008-09-13 16:24:43 +00:00
private void UseCredentials_CheckedChanged ( object sender , EventArgs e )
{
Credentials . Enabled = UseCredentials . Checked ;
}
private void UsePath_CheckedChanged ( object sender , EventArgs e )
{
TargetFolder . Enabled = BrowseTargetFolder . Enabled = UsePath . Checked ;
}
private void BrowseTargetFolder_Click ( object sender , EventArgs e )
{
if ( folderBrowserDialog . ShowDialog ( this ) == DialogResult . OK )
TargetFolder . Text = folderBrowserDialog . SelectedPath ;
}
private void UseDisk_CheckedChanged ( object sender , EventArgs e )
{
TargetDrive . Enabled = Folder . Enabled = FolderLabel . Enabled = UseDisk . Checked ;
2009-01-31 17:23:59 +00:00
RescanDrives ();
2008-09-13 16:24:43 +00:00
if ( TargetDrive . Enabled && TargetDrive . Items . Count == 0 )
{
MessageBox . Show ( this , "No removable drives were found on your system. Please enter the path manually." , Application . ProductName , MessageBoxButtons . OK , MessageBoxIcon . Information );
UsePath . Checked = true ;
}
}
}
}