예제 #1
0
        /// <summary>
        /// Foreachs the files do down to up.
        /// </summary>
        /// <param name="files">Files.</param>
        /// <param name="doFile">Do file.</param>
        public void ForeachFilesDoDownToUp(StringAtom[] files, Action <FileLoc, StringAtom> doFile)
        {
            FileLoc    loc    = new FileLoc();
            Mod        curMod = this;
            List <Mod> stack  = new List <Mod>();

            while (curMod != null)
            {
                stack.Add(curMod);
                curMod = curMod.parent;
            }
            for (int i = stack.Count - 1; i >= 0; --i)
            {
                Mod mod = stack[i];
                loc.modPath = mod.ModPath;
                for (int j = 0; j < files.Length; ++j)
                {
                    loc.uri = mod.GetFileUri(true, files[j]);
                    if (loc.uri != FileUri.UNKNOWN)
                    {
                        doFile(loc, files[j]);
                    }
                    loc.uri = mod.GetFileUri(false, files[j]);
                    if (loc.uri != FileUri.UNKNOWN)
                    {
                        doFile(loc, files[j]);
                    }
                }
            }
        }
예제 #2
0
파일: Utils.cs 프로젝트: weiwoduba258/CN
        /// <summary>
        /// Returns the directory where the assembly is located
        /// </summary>
        public static string GetLocation()
        {
            string FileLoc;

            FileLoc = Assembly.GetExecutingAssembly().Location;
            return(FileLoc.Remove(FileLoc.LastIndexOf("\\", StringComparison.Ordinal)));
        }
예제 #3
0
        public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encoding)
        {
            OtoSet otoSet;

            using (var reader = new StreamReader(stream, encoding)) {
                var fileLoc = new FileLoc {
                    file = filePath, lineNumber = 0
                };
                otoSet = new OtoSet()
                {
                    File = filePath,
                };
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    fileLoc.line = line;
                    try {
                        Oto oto = ParseOto(line);
                        if (oto != null)
                        {
                            otoSet.Otos.Add(oto);
                        }
                    } catch (Exception e) {
                        Log.Error(e, $"Failed to parse\n{fileLoc}");
                        otoSet.Errors.Add($"Oto error:\n{fileLoc}");
                    }
                    fileLoc.line = null;
                    fileLoc.lineNumber++;
                }
            }
            // Use filename as alias if not in oto.
            var knownFiles = otoSet.Otos.Select(oto => oto.Wav).ToHashSet();

            foreach (var wav in Directory.EnumerateFiles(Path.GetDirectoryName(filePath), "*.wav", SearchOption.TopDirectoryOnly))
            {
                var file = Path.GetFileName(wav);
                if (!knownFiles.Contains(file))
                {
                    var oto = new Oto {
                        Alias = Path.GetFileNameWithoutExtension(file),
                        Wav   = file,
                    };
                    oto.Phonetic = oto.Alias;
                    otoSet.Otos.Add(oto);
                }
            }
            return(otoSet);
        }
예제 #4
0
        static OtoSet ParseOtoSet(StreamReader streamReader, FileLoc fileLoc)
        {
            OtoSet otoSet = new OtoSet();

            while (!streamReader.EndOfStream)
            {
                var line = streamReader.ReadLine();
                fileLoc.line = line;
                try {
                    Oto oto = ParseOto(line);
                    if (oto != null)
                    {
                        otoSet.Otos.Add(oto);
                    }
                } catch (Exception e) {
                    throw new FileFormatException($"Failed to parse\n{fileLoc}", e);
                }
                fileLoc.line = null;
                fileLoc.lineNumber++;
            }
            return(otoSet);
        }
        static void Main()
        {
            string FileLoc;

            do
            {
                Console.Write("Enter File Location : ");
                FileLoc = Console.ReadLine().ToLower();
            } while (!File.Exists(FileLoc) || !FileLoc.EndsWith(".pdf"));


Start1:
            Console.Write("From Page : ");
            int.TryParse(Console.ReadLine(), out int from);
            if (from == default)
            {
                goto Start1;
            }


Start2:
            Console.Write("To Page : ");
            int.TryParse(Console.ReadLine(), out int to);
            if (to == default)
            {
                goto Start2;
            }


            PDFParser p = new PDFParser(FileLoc, from, to);

            p.A_SaveExcel();
            p.B_LoadExcels();


            MainIterator iter = new MainIterator(p.Table);

            p.End();
        }
예제 #6
0
        /// <summary>
        /// Gets the file location.
        /// </summary>
        /// <returns>The file location.</returns>
        /// <param name="relativePath">Relative path.</param>
        public FileLoc GetFileLoc(util.StringAtom relativePath)
        {
            FileLoc loc    = new FileLoc();
            Mod     curMod = this;

            while (curMod != null)
            {
                loc.uri = curMod.GetFileUri(true, relativePath);
                if (FileUri.UNKNOWN != loc.uri)
                {
                    loc.modPath = curMod.ModPath;
                    return(loc);
                }
                loc.uri = curMod.GetFileUri(false, relativePath);
                if (FileUri.UNKNOWN != loc.uri)
                {
                    loc.modPath = curMod.ModPath;
                    return(loc);
                }
                curMod = curMod.parent;
            }
            return(loc);
        }
예제 #7
0
        /// <summary>
        /// Fors the each file do up to down.
        /// </summary>
        /// <param name="relativePath">Relative path.</param>
        /// <param name="doFile">Do file.</param>
        ///
        public void ForEachFileDoUpToDown(StringAtom[] files, Action <FileLoc, StringAtom> doFile)
        {
            FileLoc loc    = new FileLoc();
            Mod     curMod = this;

            while (curMod != null)
            {
                loc.modPath = curMod.ModPath;
                for (int j = 0; j < files.Length; ++j)
                {
                    loc.uri = curMod.GetFileUri(true, files[j]);
                    if (loc.uri != FileUri.UNKNOWN)
                    {
                        doFile(loc, files[j]);
                    }
                    loc.uri = curMod.GetFileUri(false, files[j]);
                    if (loc.uri != FileUri.UNKNOWN)
                    {
                        doFile(loc, files[j]);
                    }
                }
                curMod = curMod.parent;
            }
        }