public void Restore( VolumeSnapshot snapshot, BaseArchive archive, string onDiskPath )
        {
            mOperation.Reset();

            mFileTotalCount = 0;
            mFilesTotalSize = 0;
            mFileRunningCount = 0;
            mFilesTotalSizeRunning = 0;

            try
            {
                mBusy = true;

                VolumeSnapshotDirectory vsd = snapshot.Root;
                mFileTotalCount = vsd.CountAllFiles( ref mFilesTotalSize );

                if ( !mOperation.CanContinue )
                    return;

                int relativePathStartIndex = vsd.RelativePath.LastIndexOf( PWLib.Platform.Windows.Path.DirectorySeparatorChar );
                if ( relativePathStartIndex < 0 )
                    relativePathStartIndex = 0;
                ProcessDirectoryRestore( vsd, archive, relativePathStartIndex, onDiskPath );
            }
            finally
            {
                mBusy = false;
            }
        }
 private VolumeSnapshotFile( VolumeSnapshot snapshot, VolumeSource source, string relativePath )
 {
     mSnapshot = snapshot;
     mRevision = null;
     mRelativePath = relativePath;
     mFileName = PWLib.Platform.Windows.Path.GetFileName( relativePath );
     mLastModified = source.GetLastWriteTimeUtc( relativePath );
     mFileSize = source.GetFileSize( relativePath );
 }
 public bool DoFullBackup( VolumeSnapshot currentSnapshot, VolumeSource source, BaseArchive archive )
 {
     mOperation.Reset();
     mFileTotalCount = currentSnapshot.FileCount;
     mFileRunningCount = 0;
     mFilesTotalSize = currentSnapshot.TotalFileSize;
     mFilesTotalSizeRunning = 0;
     mArchive = archive;
     mSource = source;
     return CopyAll( currentSnapshot.Root );
 }
        private VolumeSnapshotFile( VolumeSnapshot snapshot, XmlNode node )
        {
            mSnapshot = snapshot;
            mFileName = PWLib.XmlHelp.DirtyString( PWLib.XmlHelp.GetAttribute( node, VolumeSnapshotXml.XmlFilenameElement, "" ) );
            mRelativePath = PWLib.XmlHelp.DirtyString( PWLib.XmlHelp.GetAttribute( node, VolumeSnapshotXml.XmlRelativePathElement, "" ) );
            mRevision = VolumeSnapshotRevision.Create( PWLib.XmlHelp.GetAttribute( node, VolumeSnapshotXml.XmlRevisionElement, "" ) );

            ulong.TryParse( PWLib.XmlHelp.GetAttribute( node, VolumeSnapshotXml.XmlSizeElement, "0" ), out mFileSize );

            long ticks;
            if ( long.TryParse( PWLib.XmlHelp.GetAttribute( node, VolumeSnapshotXml.XmlLastModifiedElement, "0" ), out ticks ) )
                mLastModified = new DateTime( ticks );
        }
        private VolumeSnapshotDirectory( VolumeSnapshot snapshot, XmlNode parentNode )
        {
            mSnapshot = snapshot;
            mName = PWLib.XmlHelp.DirtyString( PWLib.XmlHelp.GetAttribute( parentNode, VolumeSnapshotXml.XmlNameElement, "" ) );
            mRelativePath = PWLib.XmlHelp.DirtyString( PWLib.XmlHelp.GetAttribute( parentNode, VolumeSnapshotXml.XmlRelativePathElement, "" ) );
            mRevision = VolumeSnapshotRevision.Create( PWLib.XmlHelp.GetAttribute( parentNode, VolumeSnapshotXml.XmlRevisionElement, "" ) );

            long ticks;
            if ( long.TryParse( PWLib.XmlHelp.GetAttribute( parentNode, VolumeSnapshotXml.XmlLastModifiedElement, "0" ), out ticks ) )
                mLastModified = new DateTime( ticks );

            foreach ( XmlNode childNode in parentNode.ChildNodes )
            {
                string lowerName = childNode.Name.ToLower();
                if ( lowerName == VolumeSnapshotXml.XmlDirectoryElement ) // Sub directories
                {
                    try
                    {
                        VolumeSnapshotDirectory subDirEntry = new VolumeSnapshotDirectory( mSnapshot, childNode );
                        mDirectories.Add( subDirEntry );
                    }
                    catch ( System.Exception e )
                    {
                        FileSync.__LogError( this, "VolumeSnapshotDirectory.BuildFromXml failed in directory '" + mName + "' '" + mRelativePath + "'", e );
                    }
                }
                else if ( lowerName == VolumeSnapshotXml.XmlFileElement ) // Files
                {
                    try
                    {
                        VolumeSnapshotFile fileEntry = VolumeSnapshotFile.BuildFromXml( mSnapshot, childNode );
                        mFiles.Add( fileEntry );
                    }
                    catch ( System.Exception e )
                    {
                        FileSync.__LogError( this, "VolumeSnapshotDirectory.BuildFromXml failed in directory on a file '" + mName + "' '" + mRelativePath + "'", e );
                    }
                }
            }
        }
        private VolumeSnapshotDirectory( VolumeSnapshot snapshot, VolumeSource source, string relativePath )
        {
            mSnapshot = snapshot;
            mRelativePath = relativePath;
            mName = mRelativePath.Length <= 1 ? "" : PWLib.Platform.Windows.Path.GetLeafName( relativePath );
            mLastModified = source.GetLastWriteTimeUtc( relativePath );// PWLib.Platform.Windows.Directory.GetLastWriteTimeUtc( rootDir );

            foreach ( string filename in source.GetRelativePathFiles( relativePath ) /* PWLib.Platform.Windows.Directory.GetFiles( rootDir ) */ )
            {
                try
                {
                    VolumeSnapshotFile fileEntry = VolumeSnapshotFile.BuildFromSource( mSnapshot, source, filename );
                    mFiles.Add( fileEntry );
                }
                catch ( System.Exception e )
                {
                    FileSync.__LogError( this, "VolumeSnapshotDirectory.BuildFromFileSystem failed on file '" + filename + "'", e );
                }
            }

            foreach ( string subDir in source.GetRelativePathDirectories( relativePath ) )
            {
                try
                {
                    if ( !IsIgnoredDirectoryName( PWLib.Platform.Windows.Path.GetLeafName( subDir ) ) )
                    {
                        VolumeSnapshotDirectory subDirEntry = new VolumeSnapshotDirectory( mSnapshot, source, subDir );
                        mDirectories.Add( subDirEntry );
                    }
                }
                catch ( System.Exception e )
                {
                    FileSync.__LogError( this, "VolumeSnapshotDirectory.BuildFromFileSystem failed on directory '" + subDir + "'", e );
                }
            }
        }
 void Spine_RestoreFinished( Volume volume, VolumeSnapshot snapshot )
 {
     mLabel.Text = mCancelledByUser ? "Transfer cancelled" : "Transfer complete";
     mButtonNext.Enabled = true;
 }
        void UpdateSnapshotToReflectBaselineRevision( VolumeSnapshot incrementalSnapshot, VolumeSnapshotRevision newRevision )
        {
            UpdateSnapshotToReflectBaselineRevisionPrivate( incrementalSnapshot.Root, newRevision );

            // save out .xml
            mDatabase.SaveSnapshotRevision( incrementalSnapshot );
        }
 public static VolumeSnapshot BuildFromSource( VolumeSource source )
 {
     VolumeSnapshot snapshot = new VolumeSnapshot( source );
     return snapshot;
 }
 void Spine_BackupFinishedWinThread( Volume volume, VolumeSnapshot snapshot, bool snapshotHasBeenSaved, bool firstBackupOnLoad )
 {
     mTreeView.SetVolumeAsBusy( volume.Descriptor, false );
 }
 void Spine_RestoreFinishedWinThread( Volume volume, VolumeSnapshot snapshot )
 {
     mTreeView.LockInterface( false );
 }
 public void InvokeRestoreProgress( Volume volume, VolumeSnapshot snapshot, ulong fileNum, ulong fileCount, ulong bytesTranferred, ulong totalBytes )
 {
     if ( RestoreProgress != null )
         RestoreProgress( volume, snapshot, fileNum, fileCount, bytesTranferred, totalBytes );
 }
 public void InvokeBackupFinished( Volume volume, VolumeSnapshot snapshot, bool snapshotHasBeenSaved, bool firstBackupOnLoad )
 {
     if ( BackupFinished != null )
         BackupFinished( volume, snapshot, snapshotHasBeenSaved, firstBackupOnLoad );
 }
 public static VolumeSnapshotFile BuildFromXml( VolumeSnapshot snapshot, XmlNode node )
 {
     return new VolumeSnapshotFile( snapshot, node );
 }
 void spine_RestoreInitStarted( Volume volume, VolumeSnapshot snapshot )
 {
     mInvokeControl.Invoke( new VolumeRestoreHandler( spine_RestoreInitStartedWinThread ), volume, snapshot );
 }
 void spine_RestoreInitStartedWinThread( Volume volume, VolumeSnapshot snapshot )
 {
     //			ShowBalloonTip( "Restore of " + volume.Descriptor.Identifier.Name + " started" );
     MainForm.Instance.SetStatusText("Restoring...");
     MainForm.Instance.SetTitleText( "Restoring", 0 );
     if ( RestoreStarted != null )
         RestoreStarted( volume, snapshot );
 }
        // This updates cached XML, will still need flushing to disk afterwards in OutputToXml()
        public void SaveSnapshotRevision( VolumeSnapshot snapshot )
        {
            VolumeSnapshotRevision revision = snapshot.Revision;
            if ( mSnapshotDictionary.ContainsKey( revision ) )
                mSnapshotDictionary[ revision ] = snapshot;
            else
                mSnapshotDictionary.Add( revision, snapshot );
            if ( !mSnapshotsStored.Contains( revision ) )
                mSnapshotsStored.Add( revision );

            PWLib.Platform.Windows.Directory.CreateDirectory( mXmlRootDir );
            XmlTextWriter xmlWriter = new XmlTextWriter( GetRevisionFileName( revision ), Encoding.Unicode );
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.WriteStartDocument();

            snapshot.OutputToXml( xmlWriter );

            xmlWriter.Close();
        }
 void Spine_BackupFinished( Volume volume, VolumeSnapshot snapshot, bool snapshotHasBeenSaved, bool firstBackupOnLoad )
 {
     mVolumeListView.Refresh();
 }
 public static VolumeSnapshot BuildFromXml( VolumeSource source, XmlNode parentNode )
 {
     VolumeSnapshot snapshot = new VolumeSnapshot( source, parentNode );
     return snapshot;
 }
 void Spine_RestoreFinishedWinThread( Volume volume, VolumeSnapshot snapshot )
 {
     ShowBalloonTip( "Restore of " + volume.Descriptor.VolumeName + " finished" );
     mProgressBar.Value = 0;
     MainForm.Instance.SetDefaultStatusText();
     MainForm.Instance.SetTitleText( "", 0 );
     Log.WriteLine( LogType.AppLog | LogType.TextLog | LogType.DebugLog, "Restoration of '" + volume.Descriptor.VolumeName + "' complete" );
     if (RestoreFinished != null)
         RestoreFinished( volume, snapshot );
 }
        public bool DoIncrementalBackup( VolumeSnapshot currentSnapshot, VolumeSnapshot mostRecentSnapshot, VolumeSource source, BaseArchive archive, out bool noChangesRequired )
        {
            noChangesRequired = false;
            mSource = source;
            mArchive = archive;

            // see if anything's changed from the last one
            currentSnapshot.Root.Revision = mostRecentSnapshot.Root.Revision;
            if ( mComparator.CompareSnapshots( mostRecentSnapshot, currentSnapshot, true ) )
            {
                FileSync.__Log( this, "Incremental comparison complete, changes detected" );
                FileSync.__Log( this, "Total file count " + mComparator.Stats.FileCount );
                FileSync.__Log( this, "Total file size " + mComparator.Stats.TotalFileSize );
                FileSync.__Log( this, "New files " + mComparator.Stats.FilesCreated );
                FileSync.__Log( this, "Removed files " + mComparator.Stats.FilesRemoved );
                FileSync.__Log( this, "Changed files " + mComparator.Stats.FilesChanged );
                FileSync.__Log( this, "New directories " + mComparator.Stats.DirectoriesCreated );
                FileSync.__Log( this, "Removed directories " + mComparator.Stats.DirectoriesRemoved );
                FileSync.__Log( this, "Files unchanged " + mComparator.Stats.FilesTheSame );
                FileSync.__Log( this, "Directories unchanged " + mComparator.Stats.DirectoriesTheSame );

                mFileTotalCount = mComparator.Stats.FileCount;
                mFilesTotalSize = mComparator.Stats.TotalFileSize;
                mFileRunningCount = 0;
                mFilesTotalSizeRunning = 0;
                mComparator.CompareSnapshots( mostRecentSnapshot, currentSnapshot, false );
                return !mOperation.Cancelled;
            }
            else
            {
                FileSync.__Log( this, "Incremental comparison complete, no changes detected" );
                noChangesRequired = true;
                return true;
            }
        }
 public static VolumeSnapshotDirectory BuildFromSource( VolumeSnapshot snapshot, VolumeSource source, string relativePath )
 {
     return new VolumeSnapshotDirectory( snapshot, source, relativePath );
 }
 public void InvokeBackupStarted( Volume volume, VolumeSnapshot snapshot, bool firstBackupOnLoad )
 {
     if ( BackupStarted != null )
         BackupStarted( volume, snapshot, false, firstBackupOnLoad );
 }
 public static VolumeSnapshotDirectory BuildFromXml( VolumeSnapshot snapshot, XmlNode parentNode )
 {
     VolumeSnapshotDirectory dirEntry = new VolumeSnapshotDirectory( snapshot, parentNode );
     return dirEntry;
 }
 public void InvokeRestoreStarted( Volume volume, VolumeSnapshot snapshot )
 {
     if ( RestoreStarted != null )
         RestoreStarted( volume, snapshot );
 }
 void Spine_RestoreFinished( Volume volume, VolumeSnapshot snapshot )
 {
     mInvokeControl.Invoke( new VolumeRestoreHandler( Spine_RestoreFinishedWinThread ), volume, snapshot );
 }
 void Spine_RestoreInitStartedWinThread( Volume volume, VolumeSnapshot snapshot )
 {
     mTreeView.LockInterface( true );
 }
        void TurnSnapshotIntoBaseline( VolumeSnapshot snapshot )
        {
            // iterate over each file in the snapshot. Copy any file that is from an
            // older revision to the current revision and update the .xml.
            List<VolumeSnapshotRevision> revisionsThatCanBeRemoved = new List<VolumeSnapshotRevision>();
            TurnSnapshotIntoBaselinePrivate( snapshot.Root, ref revisionsThatCanBeRemoved );
            snapshot.Root.Revision = snapshot.Root.Snapshot.Revision;

            RemoveOldRevisions( revisionsThatCanBeRemoved );
            mDatabase.SaveSnapshotRevision( snapshot );
        }
 public bool CompareSnapshots( VolumeSnapshot oldDb, VolumeSnapshot newDb, bool countFilesOnly )
 {
     mStats.Reset( !countFilesOnly );
     mOperation.Reset();
     return ProcessDirectory( oldDb.Root, newDb.Root );
 }
 void Spine_BackupFileFinished( Volume volume, VolumeSnapshot snapshot, ulong fileNum, ulong fileCount, ulong bytesTranferred, ulong totalBytes )
 {
     mInvokeControl.Invoke( new VolumeBackupProgressHandler( Spine_BackupFileFinishedWinThread ), volume, snapshot, fileNum, fileCount, bytesTranferred, totalBytes );
 }