示例#1
0
        public static void ImportText(string[] astr)
        {
            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (int n = 1; n < astr.Length; n++)
            {
                string strFileT = Path.GetFileName(astr[n]);
                string strDirT  = Path.GetDirectoryName(astr[n]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            Console.WriteLine("Importing text from {0} files", alsFiles.Count);

            // Attempt to process these text files/level docs

            foreach (string strTextFile in alsFiles)
            {
                string strFile = "." + Path.DirectorySeparatorChar + Path.GetFileName(strTextFile).Replace(".txt", ".ld");
                Console.Write("Writing " + strTextFile + " to " + strFile + "...");
                LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile);
                if (lvld == null)
                {
                    throw new Exception("Could not load level doc " + strFile);
                }

                StreamReader stmr = new StreamReader(strTextFile);
                string       str  = stmr.ReadToEnd();
                stmr.Close();
                str = str.Replace("\r\n", "\n");

                int ichErrorPos;
                if (!lvld.SetLevelText(str, out ichErrorPos))
                {
                    Console.WriteLine(" error at char " + ichErrorPos);
                }
                else
                {
                    lvld.Save();
                    Console.WriteLine(" saved");
                }
                lvld.Dispose();
            }
        }