91 lines
2.4 KiB
C#
91 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
using EnvDTE;
|
|
using EnvDTE80;
|
|
using EnvDTE90;
|
|
|
|
namespace MemoryViewer
|
|
{
|
|
public class MemoryUtils
|
|
{
|
|
static private EnvDTE80.DTE2 dte2 = null;
|
|
|
|
static private void CreateNewInstanceDTE()
|
|
{
|
|
|
|
if (dte2 == null)
|
|
dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.9.0");
|
|
}
|
|
|
|
static public void openFileAtLine(string filename,string linenumber)
|
|
{
|
|
try
|
|
{
|
|
CreateNewInstanceDTE();
|
|
dte2.DTE.ExecuteCommand("File.OpenFile", filename);
|
|
dte2.DTE.ExecuteCommand("Edit.GoTo", linenumber);
|
|
dte2.DTE.MainWindow.SetFocus();
|
|
dte2.DTE.MainWindow.Visible = true;
|
|
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
MessageBox.Show(ex.ToString());
|
|
}
|
|
|
|
}
|
|
static public string convertBytesToString(UInt32 bytes)
|
|
{
|
|
string tmp = "";
|
|
if (bytes < 1024)
|
|
tmp = bytes.ToString();
|
|
else if (bytes < 1024 * 1024)
|
|
tmp = (bytes / 1024).ToString() + " Kb";
|
|
else
|
|
tmp = (bytes / (1024 * 1024)).ToString() + " Mb";
|
|
|
|
return tmp;
|
|
}
|
|
|
|
static public Int32 findAllocatorId(string allocatorString)
|
|
{
|
|
foreach (MemoryFile.XALLOC_ALLOCATOR_IDS filter in Enum.GetValues(typeof(MemoryFile.XALLOC_ALLOCATOR_IDS)))
|
|
{
|
|
if (filter.ToString() == allocatorString)
|
|
{
|
|
return (Int32)filter;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
static public void readFromFile(ref List<string> dst, string filename,bool skipEmpty)
|
|
{
|
|
try
|
|
{
|
|
StreamReader SR;
|
|
string S;
|
|
SR = File.OpenText(filename);
|
|
S = SR.ReadLine();
|
|
while (S != null)
|
|
{
|
|
if (!(skipEmpty == true && filename == ""))
|
|
dst.Add(S);
|
|
|
|
S = SR.ReadLine();
|
|
}
|
|
|
|
SR.Close();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|