Beispiel #1
0
 public WebGet(FileDL fDL)
 {
     Info       = fDL;
     iRecv      = 0; iLen = 0;
     uUrl       = new Uri(Info.sFUri);
     sPath      = (Info.sFPath + Info.sFName).Replace("\\", "/");
     sRHead     = ""; sRBody = ""; State = eState.Connecting;
     bw.DoWork += new System.ComponentModel.DoWorkEventHandler(GetFile);
     bw.RunWorkerAsync();
 }
Beispiel #2
0
        public bool hGrab(string sSc)
        {
            if (!sSc.StartsWith("GRAB "))
            {
                return(false);
            }
            if (bDebug)
            {
                inf("grab ");
            }

            iGrabCnt++;
            int iThisCnt = 0;

            sSc = sSc.Substring(sSc.IndexOf(" ") + 1);
            int iTargetU = ((int)sSc[0]) - (int)'a';

            sSc = sSc.Substring(sSc.IndexOf(", ") + 2);
            int iOfs1 = Convert.ToInt32(sSc.Substring(0, sSc.IndexOf(", ")));

            sSc = sSc.Substring(sSc.IndexOf(", ") + 2);
            int iOfs2 = Convert.ToInt32(sSc.Substring(0, sSc.IndexOf(", ")));

            sSc = sSc.Substring(sSc.IndexOf(", ") + 2);

            for (int a = iOfs1; a < gsaVa[iTargetU].Length - iOfs2; a++)
            {
                iFileCnt++;
                iThisCnt++;
                string sFn  = sSc;
                string sUri = gsaVa[iTargetU][a];
                if (sFn.StartsWith("[[ofn"))
                {
                    string[] sUriParts = GUI.Split(sUri, "/");
                    string   sUPCnt    = sFn.Substring("[[ofn".Length);
                    sUPCnt = sUPCnt.Substring(0, sUPCnt.IndexOf("]]"));
                    int iUPCnt = Convert.ToInt32(sUPCnt);
                    int iUPTot = sUriParts.Length;
                    sFn = sUriParts[iUPTot - 1];
                    for (int b = 1; b < iUPCnt; b++)
                    {
                        sFn = sUriParts[iUPTot - b - 1] + "\\" + sFn;
                    }
                }
                else
                {
                    for (int b = 0; b < iChr; b++)
                    {
                        char cThis = (char)((int)'a' + b);
                        sFn = sFn.Replace("%g", "" + iGrabCnt);
                        sFn = sFn.Replace("%f", "" + iFileCnt);
                        sFn = sFn.Replace("%i", "" + a);
                        if (sFn.Contains(cThis + "]]"))
                        {
                            sFn = sFn.Replace("[[c" + cThis + "]]", saC[b]);
                            sFn = sFn.Replace("[[" + cThis + "]]", gsaV[b]);
                            sFn = sFn.Replace("[[o" + cThis + "]]", gsaOV[b]);
                            if (gsaVa[b].Length > a)
                            {
                                sFn = sFn.Replace("[[v" + cThis + "]]", gsaVa[b][a]);
                            }
                            if (gsaOVa[b].Length > a)
                            {
                                sFn = sFn.Replace("[[ov" + cThis + "]]", gsaOVa[b][a]);
                            }
                        }
                    }
                }
                //alUriLst.Add(sUri);
                //alFPaths.Add(sd.sPath + gsRoot + sFn);
                FileDL fDL = new FileDL(sUri, GUI.sAppPath + gsRoot + sFn);
                fDL.scConf = sd.scConf; DLMan.Add(fDL);
            }
            infln("- " + "Added " + iThisCnt + " files (" + iFileCnt + " in total)");
            return(true);
        }
Beispiel #3
0
        public static void tryGrab()
        {
            if (bGrab)
            {
                return;
            }
            bGrab = true;
            if (!isDowning() && isGood() &&
                alQue.Count == 0)
            {
                bGrab = false; return;
            }
            for (int a = 0; a < Cli.Length; a++)
            {
                if (Cli[a] == null ||
                    Cli[a].State == WebGet.eState.Completed ||
                    Cli[a].State == WebGet.eState.Ready)
                {
                    if (alQue.Count == 0)
                    {
                        break;
                    }
                    FileDL fDL = (FileDL)alQue[0];
                    if (a >= fDL.scConf.iThreads)
                    {
                        break;
                    }
                    alQue.RemoveAt(0);

                    PSG.infln(string.Format("  {0,-40} [", sMLen((a + 1) + ": " + fDL.sFName, 40)));
                    if (System.IO.File.Exists(fDL.sFPath + fDL.sFName))
                    {
                        PSG.inf("Exists");
                    }
                    else
                    {
                        PSG.inf("Downloading");
                        Cli[a] = new WebGet(fDL);
                    }
                }
                if (Cli[a] != null &&
                    Cli[a].State == WebGet.eState.Failed)
                {
                    string sOut     = string.Format(" {0,-40} [", sMLen((a + 1) + ": " + Cli[a].Info.sFName, 40));
                    string sAbsPath = Cli[a].Info.sFPath + Cli[a].Info.sFName;
                    if (Cli[a].Info.scConf.fcAct == ServCF.FileCut.Ignore)
                    {
                        sOut         = "/" + sOut; iCutFile_ignore++;
                        sOut        += "DC - Ignore #" + iCutFile_ignore;
                        Cli[a].State = WebGet.eState.Ready;
                        PSG.infln(sOut);
                    }
                    if (Cli[a].Info.scConf.fcAct == ServCF.FileCut.Kill)
                    {
                        sOut = "X" + sOut; iCutFile_skip++;
                        System.IO.File.Delete(sAbsPath);
                        sOut        += "DC - Delete #" + iCutFile_skip;
                        Cli[a].State = WebGet.eState.Ready;
                        PSG.infln(sOut);
                    }
                    if (Cli[a].Info.scConf.fcAct == ServCF.FileCut.RetryIgnore ||
                        Cli[a].Info.scConf.fcAct == ServCF.FileCut.RetryKill)
                    {
                        if (Cli[a].Info.fcReCnt < Cli[a].Info.scConf.fcReLim)
                        {
                            sOut = "~" + sOut; Cli[a].Info.fcReCnt++;
                            System.IO.File.Delete(sAbsPath);
                            sOut  += "DC - Retry #" + Cli[a].Info.fcReCnt;
                            Cli[a] = new WebGet(Cli[a].Info);
                            PSG.infln(sOut);
                        }
                        else
                        {
                            if (Cli[a].Info.scConf.fcAct == ServCF.FileCut.RetryIgnore)
                            {
                                sOut         = "/" + sOut; iCutFile_ignore++;
                                sOut        += "DC - Ignore #" + iCutFile_ignore;
                                Cli[a].State = WebGet.eState.Ready;
                                PSG.infln(sOut);
                            }
                            else
                            {
                                sOut = "X" + sOut; iCutFile_skip++;
                                System.IO.File.Delete(sAbsPath);
                                sOut        += "DC - Delete #" + iCutFile_skip;
                                Cli[a].State = WebGet.eState.Ready;
                                PSG.infln(sOut);
                            }
                        }
                    }
                }
            }
            bGrab = false;
        }
Beispiel #4
0
 public static void Add(FileDL fd)
 {
     alQue.Add(fd);
 }