hlFolderGetItemByPath() 공개 정적인 메소드

public static hlFolderGetItemByPath ( IntPtr pItem, string lpPath, HLFindType eFind ) : IntPtr
pItem IntPtr
lpPath string
eFind HLFindType
리턴 IntPtr
예제 #1
0
        public static void ReadScriptFromVPK <T>(string filePath, List <T> ListToInsert) where T : DotaDataObject
        {
            IntPtr root = HLLib.hlPackageGetRoot();

            IntPtr file = HLLib.hlFolderGetItemByPath(root, filePath, HLLib.HLFindType.HL_FIND_FILES);

            IntPtr stream;

            ErrorCheck(HLLib.hlPackageCreateStream(file, out stream));

            string unitsText = ReadTextFromHLLibStream(stream);

            KeyValue rootkv = KVLib.KVParser.KV1.Parse(unitsText);

            foreach (KeyValue kv in rootkv.Children)
            {
                if (!kv.HasChildren)
                {
                    continue;                  //Get rid of that pesky "Version" "1" key
                }
                T unit = typeof(T).GetConstructor(new Type[] { typeof(KeyValue) }).Invoke(new object[] { kv }) as T;

                unit.ObjectInfo.FromVPK         = true;
                unit.ObjectInfo.ObjectClass     = DotaDataObject.DataObjectInfo.ObjectDataClass.Default;
                unit.ObjectInfo.OriginatingFile = filePath;

                ListToInsert.Add(unit);
            }
            return;
        }
예제 #2
0
        public static string ReadAllText(string filePath)
        {
            IntPtr root = HLLib.hlPackageGetRoot();

            IntPtr file = HLLib.hlFolderGetItemByPath(root, filePath, HLLib.HLFindType.HL_FIND_FILES);

            IntPtr stream;

            ErrorCheck(HLLib.hlPackageCreateStream(file, out stream));

            string text = ReadTextFromHLLibStream(stream);

            return(text);
        }
예제 #3
0
        public string ReadTextFromVPK(string path)
        {
            IntPtr root = HLLib.hlPackageGetRoot();

            IntPtr file = HLLib.hlFolderGetItemByPath(root, path, HLLib.HLFindType.HL_FIND_FILES);

            IntPtr stream;

            if (ErrorCheck(HLLib.hlPackageCreateStream(file, out stream)))
            {
                return("Unable to Load File".Localize());
            }

            string text = ReadTextFromHLLibStream(stream);

            return(text);
        }
예제 #4
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (radioGcf.Checked) //Extract from gcf
            {
                Cursor = Cursors.WaitCursor;
                Settings.Default.OpenFileSetting = 0;
                HLLib.hlInitialize();
                HLLib.HLPackageType ePackageType = HLLib.HLPackageType.HL_PACKAGE_GCF;
                uint uiMode = (uint)HLLib.HLFileMode.HL_MODE_READ | (uint)HLLib.HLFileMode.HL_MODE_VOLATILE;
                uint uiPackage;
                HLLib.hlCreatePackage(ePackageType, out uiPackage);
                HLLib.hlBindPackage(uiPackage);
                if (String.IsNullOrEmpty(Settings.Default.SteamFolder))
                {
showDia:
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        if (!File.Exists(folderBrowserDialog1.SelectedPath + @"\team fortress 2 content.gcf"))
                        {
                            Cursor = Cursors.Arrow;
                            var res = MessageBox.Show(
                                "team fortress 2 content.gcf could not be found in that folder!\r\nPlease select your SteamApps folder!",
                                "TF2 Items Editor",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Error);
                            if (res == DialogResult.OK)
                            {
                                goto showDia;
                            }
                            return;
                        }
                        Settings.Default.SteamFolder = folderBrowserDialog1.SelectedPath;
                        Settings.Default.Save();
                    }
                    else
                    {
                        return;
                    }
                }
                Cursor = Cursors.WaitCursor;
                string[] dirs = Directory.GetDirectories(Settings.Default.SteamFolder);
                if (string.IsNullOrEmpty(Settings.Default.SteamUser))
                {
                    var match = new List <string>();
                    foreach (string _dir in dirs)
                    {
                        string dir = (new DirectoryInfo(_dir)).Name;
                        if (dir != "common" && dir != "media" && dir != "SourceMods")
                        {
                            match.Add(dir);
                        }
                    }
                    if (match.Count > 1)
                    {
                        using (var win = new SteamFolderSelectWindow())
                        {
                            string ret = win.ShowWindow(match);
                            if (ret == "")
                            {
                                return;
                            }
                            Settings.Default.SteamUser = ret;
                            Settings.Default.Save();
                        }
                    }
                    else if (match.Count == 1)
                    {
                        Settings.Default.SteamUser = match[0];
                        Settings.Default.Save();
                    }
                    else
                    {
                        Cursor = Cursors.Arrow;
                        MessageBox.Show("No user folders found in steamapps!",
                                        "TF2 Items Editor",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                }
                Cursor = Cursors.WaitCursor;
                string p = Settings.Default.SteamFolder + @"\team fortress 2 content.gcf";
                HLLib.hlPackageOpenFile(p, uiMode);
                IntPtr pRoot = HLLib.hlPackageGetRoot();
                IntPtr pItem = HLLib.hlFolderGetItemByPath(pRoot, filePath + file, HLLib.HLFindType.HL_FIND_ALL);
                p = Settings.Default.SteamFolder + @"\" + Settings.Default.SteamUser +
                    @"\team fortress 2" + filePath;
                Directory.CreateDirectory(p);
                if (File.Exists(p + file))
                {
                    File.Delete(p + file);
                }
                if (!HLLib.hlItemExtract(pItem, p))
                {
                    Cursor = Cursors.Arrow;
                    MessageBox.Show("Error when extracting:\r\n" +
                                    HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
                    retVal = "";
                    Close();
                }
                Cursor = Cursors.WaitCursor;
                retVal = File.Exists(p + file) ? p + file : "";
                Close();
            }
            else if (radioSteamapps.Checked) //Find in steamapps
            {
                Cursor = Cursors.WaitCursor;
                Settings.Default.OpenFileSetting = 1;
                if (Settings.Default.SteamFolder == null || Settings.Default.SteamFolder.ToString() == "")
                {
showDia:
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        if (!File.Exists(folderBrowserDialog1.SelectedPath + @"\team fortress 2 content.gcf"))
                        {
                            Cursor = Cursors.Arrow;
                            var res = MessageBox.Show(
                                "team fortress 2 content.gcf could not be found in that folder!\r\nPlease select your steamapps folder!",
                                "TF2 Items Editor",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Error);
                            if (res == DialogResult.OK)
                            {
                                goto showDia;
                            }
                            return;
                        }
                        Settings.Default.SteamFolder = folderBrowserDialog1.SelectedPath;
                        Settings.Default.Save();
                    }
                    else
                    {
                        return;
                    }
                }
                Cursor = Cursors.WaitCursor;
                string[] dirs = Directory.GetDirectories(Settings.Default.SteamFolder);
                if (string.IsNullOrEmpty(Settings.Default.SteamUser))
                {
                    var match = new List <string>();
                    foreach (string _dir in dirs)
                    {
                        string dir = (new DirectoryInfo(_dir)).Name;
                        if (dir != "common" && dir != "media" && dir != "SourceMods")
                        {
                            match.Add(dir);
                        }
                    }
                    if (match.Count > 1)
                    {
                        using (var win = new SteamFolderSelectWindow())
                        {
                            string ret = win.ShowWindow(match);
                            if (ret == "")
                            {
                                return;
                            }
                            Settings.Default.SteamUser = ret;
                            Settings.Default.Save();
                        }
                    }
                    else if (match.Count == 1)
                    {
                        Settings.Default.SteamUser = match[0];
                        Settings.Default.Save();
                    }
                    else
                    {
                        Cursor = Cursors.Arrow;
                        MessageBox.Show("No user folders found in steamapps!",
                                        "TF2 Items Editor",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                }
                string p = Settings.Default.SteamFolder + @"\" + Settings.Default.SteamUser +
                           @"\team fortress 2" + filePath + file;
                retVal = File.Exists(p) ? p : "";
                if (!File.Exists(p))
                {
                    Cursor = Cursors.Arrow;
                    MessageBox.Show("Couldn't find " + file + "!\r\nPlease make sure it is present in " + p,
                                    "TF2 Items Editor",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
                Close();
            }
            else if (radioManual.Checked) //Find manually
            {
                Settings.Default.OpenFileSetting = 2;
                openFileDialog1.Filter           = file.Split('.')[1] + " files|*." + file.Split('.')[1];
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    retVal = openFileDialog1.FileName;
                    Close();
                }
                else
                {
                    retVal = "";
                    return;
                }
            }
        }