04-15-2015, 03:42 PM
(04-15-2015, 02:45 PM)YinYin Wrote: With the lf2.exe marker it's all snappy and fast, with a quick note on what to do in case no marker was found.I tried this code out:
CSHARP-Code:
using System.IO; using System.Diagnostics; using System.Collections.Generic; namespace StupidLanguage { class Bmp { public Bmp(string path_) { path = path_; } public string path; } class BmpBegin { public BmpBegin() { bmps.Add(new Bmp("sprite\\sys\\knight_0.bmp")); bmps.Add(new Bmp("sprite\\sys\\knight_1.bmp")); bmps.Add(new Bmp("sprite\\sys\\knight_2.bmp")); bmps.Add(new Bmp("sprite\\sys\\knight_0b.bmp")); bmps.Add(new Bmp("sprite\\sys\\knight_1b.bmp")); bmps.Add(new Bmp("sprite\\sys\\knight_2b.bmp")); } public List<Bmp> bmps = new List<Bmp>(); } class ObjectFile { public BmpBegin bmp_begin = new BmpBegin(); } class Global { public ObjectFile objectfile = new ObjectFile(); } class Program { static Global global = new Global(); static void Main(string[] args) { Stopwatch Countdown = Stopwatch.StartNew(); string a = open("D:\\LF2\\LF2_v2.0a\\data\\knight.dat"); Countdown.Stop(); System.Console.WriteLine(Countdown.Elapsed); System.Console.WriteLine(a); } private static string open(string args) { string lf2root = Path.GetDirectoryName(args) + "\\"; bool DirectoryFound = false; do { DirectoryFound = true; for (int i = 0; i < global.objectfile.bmp_begin.bmps.Count; i++) { if (!File.Exists(lf2root + global.objectfile.bmp_begin.bmps[i].path)) { DirectoryFound = false; break; } } } while (!DirectoryFound && UpOneDirectory(ref lf2root)); if (!DirectoryFound) lf2root = "\\\\"; //indication of unfound root directory from previous implementation /*/get lf2.exe path - previous implementation lf2root = Path.GetDirectoryName(args) + "\\lf2.exe"; while (!File.Exists(lf2root) && lf2root.Length > 10) lf2root = lf2root.Substring(0, lf2root.Length - new DirectoryInfo(Path.GetDirectoryName(lf2root)).Name.Length - Path.GetFileName(lf2root).Length - 2) + "\\lf2.exe"; lf2root = Path.GetDirectoryName(lf2root) + "\\";*/ return lf2root; } private static bool UpOneDirectory(ref string lf2root) { if (lf2root.Length > 4) { lf2root = lf2root.Substring(0, lf2root.Length - new DirectoryInfo(Path.GetDirectoryName(lf2root + "\\")).Name.Length); return true; } return false; } } } |
It runs in 0.0004920 seconds on my PC. How long does it take on yours?
Age ratings for movies and games (and similar) have never been a good idea.
One can learn a lot from reinventing wheels.
An unsound argument is not the same as an invalid one.
volatile in C++ does not mean thread-safe.
Do not make APIs unnecessarily asynchronous.
Make C++ operator > again
Trump is an idiot.
One can learn a lot from reinventing wheels.
An unsound argument is not the same as an invalid one.
volatile in C++ does not mean thread-safe.
Do not make APIs unnecessarily asynchronous.
Make C++ operator > again
Trump is an idiot.