Пример #1
0
        private void AddFile(string filename)
        {
            string extn = Path.GetExtension(filename);

            extn = extn.ToLower();
            if ((extn != ".zip") && (extn != ".7z"))
            {
                return;
            }

            if ((extn == ".zip") && (Trrntzip.Program.InZip == zipType.sevenzip))
            {
                return;
            }
            if ((extn == ".7z") && (Trrntzip.Program.InZip == zipType.zip))
            {
                return;
            }

            TzFile tmpFile = new TzFile(filename);
            int    found   = _fileList.Search(tmpFile, out int index);

            if (found != 0)
            {
                _fileList.Add(index, tmpFile);
            }
        }
Пример #2
0
        public int Search(TzFile value, out int index)
        {
            int intBottom = 0;
            int intTop    = _tzFiles.Count;
            int intMid    = 0;
            int intRes    = -1;

            //Binary chop to find the closest match
            while ((intBottom < intTop) && (intRes != 0))
            {
                intMid = (intBottom + intTop) / 2;

                intRes = Compare(value, _tzFiles[intMid]);
                if (intRes < 0)
                {
                    intTop = intMid;
                }
                else if (intRes > 0)
                {
                    intBottom = intMid + 1;
                }
            }
            index = intMid;

            // if match was found check up the list for the first match
            if (intRes == 0)
            {
                int intRes1 = 0;
                while ((index > 0) && (intRes1 == 0))
                {
                    intRes1 = Compare(value, _tzFiles[index - 1]);
                    if (intRes1 == 0)
                    {
                        index--;
                    }
                }
            }
            // if the search is greater than the closest match move one up the list
            else if (intRes > 0)
            {
                index++;
            }

            return(intRes);
        }
Пример #3
0
 private static int Compare(TzFile var1, TzFile var2)
 {
     return(string.Compare(var1.Filename, var2.Filename, StringComparison.Ordinal));
 }
Пример #4
0
 public void Add(int index, TzFile value)
 {
     _tzFiles.Insert(index, value);
 }