public static ArrayList GetNewFiles(ArrayList localFiles, ArrayList remoteFiles, bool checkOnlyPath, bool isTemp)
        {
            if ((remoteFiles == null) || (remoteFiles.Count <= 0))
            {
                return(null);
            }
            if ((localFiles == null) || (localFiles.Count <= 0))
            {
                return(remoteFiles);
            }
            ArrayList newFiles = new ArrayList();

            for (int i = 0; i < remoteFiles.Count; i++)
            {
                RemoteFile rm    = (RemoteFile)remoteFiles[i];
                bool       found = false;
                for (int j = 0; j < localFiles.Count; j++)
                {
                    RemoteFile lc          = (RemoteFile)localFiles[j];
                    bool       sameFile    = false;
                    bool       sameVersion = false;
                    bool       sameName    = lc.IsSamePathFile(rm, ref sameVersion);
                    if (checkOnlyPath)
                    {
                        sameFile = lc.name.Equals(rm.name);
                    }
                    else
                    {
                        sameFile = lc.IsSameFile(rm);
                    }
                    if (sameFile)
                    {
                        if (checkOnlyPath)
                        {
                            found = true;
                        }
                        else
                        {
                            string file   = rm.GetPath(isTemp);
                            bool   exists = File.Exists(file);
                            if (exists)
                            {
                                if (rm.ValidateSize(file))
                                {
                                    if (rm.ShouldCheckCrc)
                                    {
                                        if (Crc.HashFile(file, false).ToLower().Equals(rm.crc))
                                        {
                                            found = true;
                                        }
                                    }
                                    else
                                    {
                                        found = true;
                                    }
                                }
                            }
                            else
                            {
                                // handle partial files
                                string tempFile   = HttpGetter.GetTempFilePath(file);
                                bool   tempExists = File.Exists(tempFile);
                                if (tempExists)
                                {
                                    if (rm.IsSizeValid())
                                    {
                                        if (rm.ValidateSize(tempFile))
                                        {
                                            if (rm.ShouldCheckCrc)
                                            {
                                                if (Crc.HashFile(tempFile, false).ToLower().Equals(rm.crc))
                                                {
                                                    File.Move(tempFile, file);
                                                    found = true;
                                                }
                                                else
                                                {
                                                    Utils.DeleteFile(tempFile);
                                                }
                                            }
                                            else
                                            {
                                                File.Move(tempFile, file);
                                                found = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                    else
                    {
                        if (sameName && !sameVersion)
                        {
                            string file = rm.GetPath(isTemp);
                            Utils.DeleteFile(HttpGetter.GetTempFilePath(file));
                        }
                    }
                }
                if (!found)
                {
                    newFiles.Add(rm);
                }
            }
            return(newFiles);
        }
        public static ArrayList Load(StreamReader sr, ref ArrayList fileAssoc)
        {
            if (fileAssoc == null)
            {
                fileAssoc = new ArrayList();
            }
            fileAssoc.Clear();

            ArrayList files     = new ArrayList();
            Hashtable variables = new Hashtable();
            string    crc       = string.Empty;
            Crc       hash      = new Crc(true);

            for (string line = sr.ReadLine(); line != null; line = sr.ReadLine())
            {
                line = line.Trim(' ', '\t', '\r', '\n');
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                else if (line.StartsWith(Crc.Prefix))
                {
                    crc = line.Substring(Crc.Prefix.Length);
                    continue;
                }
                else if (line.StartsWith("#") && !line.StartsWith("##"))
                {
                    continue;
                }
                else if (line.StartsWith("$$"))
                {
                    int idx = line.IndexOf('=');
                    if (idx < 0)
                    {
                        continue;
                    }
                    string key = line.Substring(1, idx - 1).Trim();
                    string val = line.Substring(idx + 1).Trim();
                    variables[key] = val;
                    continue;
                }

                foreach (string k in variables.Keys)
                {
                    line = line.Replace(k, (string)variables[k]);
                }

                if (line.StartsWith(FileAssoc.Prefix))
                {
                    FileAssoc fa = new FileAssoc();
                    fa.FromString(line);
                    if (fa.Valid)
                    {
                        hash.Update(fa.ToString());
                        fileAssoc.Add(fa);
                    }
                    continue;
                }

                RemoteFile rm = new RemoteFile();
                rm.Init(line);
                if (rm.Valid)
                {
                    // add starter only if new
                    if (rm.IsStarterReplacer)
                    {
                        if (rm.version.Equals(Config.Default.StarterLastVersion))
                        {
                            continue;
                        }
                        else
                        {
                            string newExePath = Config.Default.GetNewStarterPath();
                            if (File.Exists(newExePath))
                            {
                                string newExeVersion = Config.Default.StarterNewVersion;
                                if (newExeVersion.Equals(rm.version))
                                {
                                    // already downloaded this starter version
                                    continue;
                                }
                            }
                        }
                    }
                    hash.Update(rm.ToString());
                    files.Add(rm);
                }
            }
            if (!string.IsNullOrEmpty(crc))
            {
                string newCrc = hash.GetValue();
                if (!crc.ToLower().Equals(newCrc))
                {
                    throw new Exception(Str.Def.Get(Str.FailedCrc));
                }
            }
            return(files);
        }