Beispiel #1
0
        private void _dc_Ended(IDataOpItem item)
        {
            if (item is DownloadDataItem)
            {
                DownloadDataItem ddi = item as DownloadDataItem;
                if (ddi.Success)
                {
                    if (_excludedItems.Contains(Kits.GetFilename(ddi.Target)))
                    {
                        return;
                    }
                    _downedCount++;
                    //unpackage
                    string target = ddi.Target.Replace(@"\" + _temp, "");

                    string dir = (new FileInfo(target)).DirectoryName;
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    try
                    {
                        int l = ResourcePackage.Unpackage(ddi.Target, target);
                        Notified?.Invoke(CVRDownloadResult.Finished, new FinishedItem {
                            Name = target, Length = l
                        });
                    }
                    catch
                    {
                        Notified?.Invoke(CVRDownloadResult.UnpackageHappened, target);
                    }

                    if (_requestedCount == _downedCount)
                    {
                        string targetemp = Path.Combine(Target, _temp);
                        if (Directory.Exists(targetemp))
                        {
                            Kits.DeleteDirectory(targetemp);
                        }

                        Notified?.Invoke(CVRDownloadResult.Completed, _downedCount);
                    }
                }
                else
                {
                    Notified?.Invoke(CVRDownloadResult.DownloadHappened, ddi.Source);
                }
            }
        }
Beispiel #2
0
        private void _dc_Ended(IDataOpItem item)
        {
            if (item is DownloadDataItem)
            {
                DownloadDataItem ddi = item as DownloadDataItem;
                if (ddi.Success)
                {
                    string crc = FileMD5.Create(ddi.Target);
                    if (crc == ddi.Crc)
                    {
                        string localPathfile = _dc.GetLocalPathfile(ddi.Source);

                        try
                        {
                            if (LocalFile)
                            {
                                ResourcePackage.Unpackage(ddi.Target, localPathfile);
                                Notified?.Invoke(CVResRequestResult.RequestFileSucceed, localPathfile);
                            }
                            else
                            {
                                byte[] buff = ResourcePackage.Unpackage(File.ReadAllBytes(ddi.Target));
                                Notified?.Invoke(CVResRequestResult.RequestDataSucceed, buff);
                            }
                        }
                        catch (NullReferenceException)
                        {
                            Notified?.Invoke(CVResRequestResult.UnpackageFailed, localPathfile);
                        }
                        catch (IOException)
                        {
                            Notified?.Invoke(CVResRequestResult.WriteFailed, localPathfile);
                        }
                    }
                    else
                    {
                        Notified?.Invoke(CVResRequestResult.CrcFailded, ddi.Message);
                    }
                }
                else
                {
                    Notified?.Invoke(CVResRequestResult.DownloadFailed, ddi.Message);
                }
            }
        }