Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Invented by gigajew
- namespace Recovery.RuneScape {
- public static class OSBuddy {
- private static string UsernameFile = Environment.GetEnvironmentVariable("USERPROFILE") + "\\OSBuddy\\settings\\Remember Login Name.settings";
- public static string GetUsername() {
- var fileInfo = new FileInfo(UsernameFile);
- if(fileInfo.Exists) {
- using (FileStream fs = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
- using (StreamReader sr = new StreamReader(fs)) {
- var line = sr.ReadLine();
- var startIndex = IndexOfAny(line, (char) 34, 18) + 1;
- var endIndex = line.IndexOf((char) 34, startIndex + 1);
- return line.Substring(startIndex, endIndex - startIndex);
- }
- }
- }
- return default(string);
- }
- private static int IndexOfAny(string haystack, char needle, int offset = 0) {
- var index = haystack.IndexOf(needle);
- for (int i = 0; i < offset; i++) {
- index = haystack.IndexOf(needle, index + 1);
- }
- return index;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement