PRoConEvents.MULTIbalancer.MergeWithFile C# (CSharp) Method

MergeWithFile() private method

private MergeWithFile ( String var, List list ) : void
var String
list List
return void
        private void MergeWithFile(String[] var, List<String> list)
        {
            if (var == null || list == null) return;
            list.Clear();
            int n = 0;
            foreach (String s in var) {
            if (n == 0 && Regex.Match(s, @"^\s*<").Success) {
            String fileName = s.Replace("<", String.Empty);
            String path = Path.Combine("Configs", fileName);

            try {
                if (!Path.IsPathRooted(path)) path = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, path);
                Byte[] buffer = new Byte[128]; // 64k buffer
                int got = 0;
                UTF8Encoding utf = new UTF8Encoding(false, true);
                StringBuilder sb = new StringBuilder();

                using (FileStream fs = File.Open(path, FileMode.Open)) {
                    while ((got = fs.Read(buffer, 0, buffer.Length-1)) > 0) {
                        String tmp = utf.GetString(buffer, 0, got);
                        foreach (Char c in tmp) {
                            if (c == '\n') {
                                list.Add(sb.ToString());
                                sb = new StringBuilder();
                            } else if (c == '\r') {
                                continue;
                            } else {
                                sb.Append(c);
                            }
                        }
                    }
                    if (sb.Length > 0) {
                        list.Add(sb.ToString());
                    }
                }
            } catch (Exception ex) {
                ConsoleError("Unable to merge file: " + fileName);
                ConsoleError(ex.GetType().ToString() + ": " + ex.Message);
            }
            if (list.Count > 0) {
                ConsoleDebug("MergeWithFile ^b" + fileName + "^n contained:");
                foreach (String mf in list) {
                    ConsoleDebug(mf);
                }
                ConsoleDebug("MergeWithFile, end of ^b" + fileName + "^n");
            }
            } else {
            list.Add(s);
            }
            n = n + 1;
            }
        }
MULTIbalancer