public void Test_1()
        {
            _SpaceAvailable = FileInternalToolBox.AvailableFreeSpace("C:\\");

            SpaceChecker target = new SpaceChecker("C:\\", 2 * _SpaceAvailable);
            target.DiskName.Should().Be("C:\\");
            target.SizeAvailable.SizeInByte.Should().Be(_SpaceAvailable);
            (-target.Delta).SizeInByte.Should().Be(_SpaceAvailable);
            target.OK.Should().BeFalse();
            string ts = target.ToString();
            ts.Should().Contain("Missing");
        }
        public void Test_0()
        {
            _SpaceAvailable = FileInternalToolBox.AvailableFreeSpace("C:\\");

            SpaceChecker target = new SpaceChecker("C:\\", 0);
           target.DiskName.Should().Be("C:\\");
           target.SizeAvailable.SizeInByte.Should().Be(_SpaceAvailable);
           target.Delta.SizeInByte.Should().Be(_SpaceAvailable);
           target.OK.Should().BeTrue();
           string ts = target.ToString();
           ts.Should().Contain("Remaining");
        }
        public void Test_3()
        {
            _SpaceAvailable = FileInternalToolBox.AvailableFreeSpace("C:\\");

            string path = this.GetFileInName("A - B.mp3");
            File.Exists(path).Should().BeTrue();

            SpaceChecker target = new SpaceChecker("C:\\",path.SingleItemCollection());
            //A - B.mp3 106KB 108.943 bytes 

            target.SizeAvailable.SizeInByte.Should().Be(_SpaceAvailable);
            target.SizeNeeded.SizeInByte.Should().Be(108943);
            target.Delta.SizeInByte.Should().Be(_SpaceAvailable - 108943);
            target.OK.Should().BeTrue();
            string ts = target.ToString();
            ts.Should().Contain("Remaining");
        }
        protected override ImporterConverterAbstract GetNext(IEventListener iel, CancellationToken iCancellationToken)
        {
            if (iCancellationToken.IsCancellationRequested)
            {
                return null;
            }

            SpaceChecker sc = new SpaceChecker(Context.ConvertManager.PathFromOutput(_ListMusic[0], _ClueName),
              _ListMusic);

            if (!sc.OK)
            {
                iel.Report(new NotEnougthSpace(sc.ToString()));
                return null;
            }

            try
            {
                _TargetConvertedMusic = ConvertMusic(iel, iCancellationToken).ToList();
            }
            catch (ImportExportException iee)
            {
                throw iee;
            }
            catch (Exception e)
            {
                Trace.WriteLine(string.Format("Exception during music convestion, could be ok if this a cancellation exception {0}", e));
                return null;
            }

            if (iCancellationToken.IsCancellationRequested)
            {
                return null;
            }

            if (_TargetConvertedMusic.Count == 0)
            {
                return null;
            }

            return new MusicImporter(_TargetConvertedMusic, _ListImage, _ClueName);
        }
 private void UpdateSC()
 {
     SpaceCheck = IsPertinent? new SpaceChecker(_DN, _Length) : null;
 }
 public bool End()
 {
     _SC = new SpaceChecker(_DN, _Length);
     return _SC.OK;
 }
        protected override ImporterConverterAbstract GetNext(IEventListener iel, CancellationToken iCancellationToken)
        {
            if (_Done)
                throw new InvalidOperationException("reentrance");

            _Done = true;

            if (!Analyse())
            {
                //Cue does not match..let's do the easy way.
                return new MusicConverterImporter(_IMusicConverter, _MusicandCueFile.Select(i => i.Item1).ToList(), _ListImage, _ClueName);
            }

            foreach (Tuple<string, AlbumDescriptor> MAC in _MusicandCueFile)
            {
                _MusicConverted.Add(MAC.Item1);
                _MusicConverted.Add(MAC.Item2.CUESheetFileName);
            }

            List<TrackConverted> tracks = new List<TrackConverted>();

            SpaceChecker sc = new SpaceChecker(Context.ConvertManager.PathFromOutput(_MusicandCueFile[0].Item1, _ClueName),
                from mac in _MusicandCueFile select mac.Item1);

            if (!sc.OK)
            {
                iel.Report(new NotEnougthSpace(sc.ToString()));
                return null;
            }

            if (iCancellationToken.IsCancellationRequested)
            {
                return null;
            }

            foreach (Tuple<string, AlbumDescriptor> MAC in _MusicandCueFile)
            {
                string MusicPath = MAC.Item1;
                AlbumDescriptor Cs = MAC.Item2;

                int Current = 1;
                iel.Report(new ConvertProgessEventArgs(_ClueName.DisplayName, Current, Cs.RawTrackDescriptors.Count));

                bool OK = false;

                using (IMusicfilesConverter imcc = _IMusicConverter.GetMusicConverter(MusicPath, Cs.RawTrackDescriptors, Context.ConvertManager.PathFromOutput(MusicPath, _ClueName), Context.Folders.Temp))
                {

                    IProgress<TrackConverted> progress = new SimpleProgress<TrackConverted>
                    ( (e) =>
                    {
                        iel.Report(new ConvertProgessEventArgs(_ClueName.DisplayName, ++Current, Cs.RawTrackDescriptors.Count));
                        if (e.OK)
                        {
                            tracks.Add(e);
                            AddConvertedFiles(MusicPath, e.Track.Path);
                        }
                        else
                            iel.OnFactorisableError<UnableToConvertFile>(e.Track.Name);
                    });

                    OK = imcc.ConvertTomp3(progress, iCancellationToken);
                }
            }

            if (iCancellationToken.IsCancellationRequested)
            {
                return null;
            }

            return new MusicWithMetadaImporter((from t in tracks select t.Track).ToArray<ITrackDescriptor>(), _ListImage, _ClueName); ;
        }
        public bool Extract(IEventListener Listener, CancellationToken iCancellationToken)
        {
            if (!CanBeImported)
            {
                Listener.Report(new FileTooLongArgs((_RarContext as IImportHelper).DisplayName));
                return false;
            }

            if (!ContainsMusic)
            {
                Listener.Report(new NoMusicImportErrorEventArgs((_RarContext as IImportHelper).DisplayName));
                return false;
            }

            //check available space
            SpaceChecker sc = new SpaceChecker(Root, _Sex.UnpackedSize * (ContainsCompressedMusic ? 2 : 1));

            if (!sc.OK)
            {
                Listener.Report(new NotEnougthSpace(sc.ToString()));
                return false;
            }

            return PrivateDecompactor(Listener, iCancellationToken);
        }