initial oogynize check in _ this actually used to work!

This commit is contained in:
2016-02-14 21:16:31 -08:00
parent b183af5d55
commit 532ea133bc
337 changed files with 30692 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Win32;
using System.Reflection;
using System.Diagnostics;
namespace Ooganizer.Platform.Utilities
{
public class DebugLogger
{
private static string s_strFileNPath = "";
private static FileM s_fileM = null;
private static LogInstantiator s_LogI = null;
private static int s_LoadTime = 0;
private static bool s_firstTime = true;
/// <summary>
/// Use the Log(string line) method to quickly write to a temp log file in the current assembly directory
/// </summary>
static DebugLogger()
{
if (s_LogI == null)
{
int timebefore = System.Environment.TickCount;
s_LogI = new LogInstantiator();
s_LoadTime = System.Environment.TickCount - timebefore;
}
if (s_fileM == null)
s_fileM = new FileM(s_LogI.strFileName, "log", s_LogI.strDirectoryPath, true);
if(s_strFileNPath == "")
s_strFileNPath = s_fileM.PathNFile;
}
public static void Log(string line)
{
if (s_firstTime)
{
//s_fileM.WriteLineUTF8("EasyLogger's Logger.cs was loaded in " + s_LoadTime.ToString() + " miliseconds");
s_firstTime = false;
}
s_fileM.WriteLineUTF8(line);
}
/// <summary>
/// Small Helper class in order to get the location of the currently running assembly
/// </summary>
private class LogInstantiator
{
public string strFileName;
public string strDirectoryPath;
private static RegistryKey s_OogyRootKey;
public LogInstantiator()
{
// For Random File names ~shouldn't be used anymore
//string strRandomFileName = Path.GetRandomFileName();
//strRandomFileName = strRandomFileName.Substring(0, (strRandomFileName.Length - 4)); // stripe extension (.xyz)
//strFileName = strRandomFileName;
// Find the Calling Assembly that is NOT this one
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame;
MethodBase stackFrameMethod;
string typeName;
int framecount = 3;
stackFrame = stackTrace.GetFrame(framecount);
stackFrameMethod = stackFrame.GetMethod();
typeName = stackFrameMethod.ReflectedType.FullName;
// *IMP* Use the calling Assembly Type Name as the file name
strFileName = typeName;
// *Work-Around*, we can't have a circular reference with InstallationSpec, so we just
// have to Query for the LogPath Directly instead of using Platform.InstallationSpec
s_OogyRootKey = Registry.LocalMachine.OpenSubKey("Software\\Ooganizer",false);
if (s_OogyRootKey != null)
{
object keyvalue = s_OogyRootKey.GetValue("LogPath");
if ((keyvalue != null) && (keyvalue.ToString() != ""))
strDirectoryPath = keyvalue.ToString();
}
}
}
}
}

154
Platform/Utilities/FileM.cs Normal file
View File

@@ -0,0 +1,154 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Ooganizer.Platform.Utilities
{
public class FileM
{
private string m_sFileName;
private string m_sFileType;
private string m_sFileDirPath;
//Flags
private bool m_bIsFileCreated = false;
private bool m_bOverideExisting = true;
private bool m_bDeleteOnDestruct = false;
// Creates Temporary File by Default
public FileM(string FileType)
{
m_sFileName = Path.GetRandomFileName();
m_sFileType = FileType;
m_sFileDirPath = Path.GetTempPath();
m_bDeleteOnDestruct = true;
}
public FileM(string FileType, bool bDontDeleteOnDestruct)
{
m_sFileName = Path.GetRandomFileName();
m_sFileType = FileType;
m_sFileDirPath = Path.GetTempPath();
m_bDeleteOnDestruct = !bDontDeleteOnDestruct;
}
public FileM(string FileName, string FileType, string DirectoryPath, bool OverideExisting)
{
m_sFileName = FileName;
m_sFileType = FileType;
if (!Directory.Exists(DirectoryPath))
{
Directory.CreateDirectory(DirectoryPath);
}
m_sFileDirPath = DirectoryPath + "\\";
m_bOverideExisting = OverideExisting;
}
~FileM()
{
if (m_bDeleteOnDestruct)
{
File.Delete(this.PathNFile);
}
}
public void WriteLineA(string line)
{
FileStream fs = CreateFile();
StreamWriter sw = new StreamWriter(fs, Encoding.ASCII);
sw.WriteLine(line);
sw.Flush();
sw.Close();
fs.Close();
}
public void WriteLineA(string[] lines)
{
FileStream fs = CreateFile();
StreamWriter sw = new StreamWriter(fs, Encoding.ASCII);
foreach (string line in lines)
{
sw.WriteLine(line);
}
sw.Flush();
sw.Close();
fs.Close();
}
public void WriteLineUTF8(string line)
{
FileStream fs = CreateFile();
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
sw.WriteLine(line);
sw.Flush();
sw.Close();
fs.Close();
}
public void WriteLineUTF8(string[] lines)
{
FileStream fs = CreateFile();
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
foreach (string line in lines)
{
sw.WriteLine(line);
}
sw.Flush();
sw.Close();
fs.Close();
}
public void DeleteIfExists()
{
if (File.Exists(this.PathNFile))
{
File.Delete(this.PathNFile);
}
}
private FileStream CreateFile()
{
if (!m_bIsFileCreated && m_bOverideExisting)
{
m_bIsFileCreated = true;
return (new FileStream(this.PathNFile, FileMode.Create));
}
else
{
return (new FileStream(this.PathNFile, FileMode.Append));
}
}
// public properties
public string FileName
{
get
{
return (this.FileName);
}
}
public string DirectoryPath
{
get
{
return (this.m_sFileDirPath);
}
}
public string PathNFile
{
get
{
return (m_sFileDirPath + m_sFileName + "." + m_sFileType);
}
}
}
}

191
Platform/Utilities/RegM.cs Normal file
View File

@@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
namespace Foo.Platform.Utilities
{
public enum HKEYRoot
{
ClassesRoot,
CurrentUser,
LocalMachine,
}
public enum KeySub
{
Software,
Custom
}
public class RegM
{
private RegistryKey _RegKey;
/// <summary>
/// Use this to Open/Automatically Create a Registry Key
/// </summary>
/// <param name="root">specify registry root</param>
/// <param name="sub">specify a sub or custom</param>
/// <param name="Key">key you want to open / create </param>
/// <param name="bWrite">true if you plan on writing to it</param>
public RegM(HKEYRoot root, KeySub sub, string Key, bool bWrite)
{
string KeyToOpen = String.Empty;
if (sub == KeySub.Custom)
KeyToOpen = Key;
else
KeyToOpen = sub.ToString() + "\\" + Key;
RegistryKeyPermissionCheck permission = RegistryKeyPermissionCheck.ReadSubTree;
if (bWrite)
permission = RegistryKeyPermissionCheck.ReadWriteSubTree;
// Open/Create if it doesn't exist, the Proper Key
switch (root)
{
case HKEYRoot.ClassesRoot:
_RegKey = Registry.ClassesRoot.CreateSubKey(KeyToOpen, permission);
break;
case HKEYRoot.CurrentUser:
_RegKey = Registry.CurrentUser.CreateSubKey(KeyToOpen, permission);
break;
case HKEYRoot.LocalMachine:
_RegKey = Registry.LocalMachine.CreateSubKey(KeyToOpen, permission);
break;
}
}
#region GetValue Registry Functions
public bool GetVal_String(string strValKey, out string StringValue)
{
StringValue = String.Empty;
try
{
object keyvalue = null;
keyvalue = _RegKey.GetValue(strValKey);
if (isValidStr(keyvalue))
StringValue = keyvalue.ToString();
return true;
}
catch (Exception) { /* ignore */ }
return false;
}
public bool GetVal_Bool(string strValKey, out bool BoolValue)
{
BoolValue = false;
try
{
string StringValue;
if (GetVal_String(strValKey, out StringValue) &&
!String.IsNullOrEmpty(StringValue))
BoolValue = Boolean.Parse(StringValue);
return true;
}
catch (Exception) { /* ignore */ }
return false;
}
public bool GetVal_Int(string strValKey, out int IntValue)
{
IntValue = 0;
try
{
string StringValue;
if (GetVal_String(strValKey, out StringValue) &&
!String.IsNullOrEmpty(StringValue))
IntValue = int.Parse(StringValue);
return true;
}
catch (Exception) { /* ignore */ }
return false;
}
public bool GetVal_Binary(string strValKey, out byte[] ByteValue)
{
ByteValue = null;
try
{
string StringValue;
if (GetVal_String(strValKey, out StringValue) &&
!String.IsNullOrEmpty(StringValue))
{
ByteValue = new Byte[StringValue.Length];
for (int i = 0; i < ByteValue.Length; ++i)
{
string strByte = Convert.ToString(StringValue[i]);
ByteValue[i] = byte.Parse(strByte);
}
}
return true;
}
catch (Exception) { /* ignore */ }
return false;
}
#endregion
#region SetValue Registry Functions
public bool SetVal_String(string strValKey, string StringValue)
{
try
{
_RegKey.SetValue(strValKey, StringValue, RegistryValueKind.String);
return true;
}
catch (Exception) { /* ignore */ }
return false;
}
public bool SetVal_Bool(string strValKey, bool BoolValue)
{
try
{
_RegKey.SetValue(strValKey, BoolValue.ToString(), RegistryValueKind.String);
return true;
}
catch (Exception) { /* ignore */ }
return false;
}
public bool SetVal_Int(string strValKey, int DwordValue)
{
try
{
_RegKey.SetValue(strValKey, DwordValue, RegistryValueKind.DWord);
return true;
}
catch (Exception) { /* ignore */ }
return false;
}
public bool SetVal_Binary(string strValKey, byte[] ByteValue)
{
try
{
_RegKey.SetValue(strValKey, ByteValue, RegistryValueKind.Binary);
return true;
}
catch (Exception) { /* ignore */ }
return false;
}
#endregion
/// <returns>Returns true if passed in object is valid and not ""</returns>
private bool isValidStr(object oToValidate)
{
if ((oToValidate != null) && (oToValidate.ToString() != ""))
return true;
else
return false;
}
}
}