private void framesToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            Frames f = new Frames();

            f.Filename = Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + Frames.FileExtension;
            f.FilePath = GetFullPathForNode(tvAssets.SelectedNode);
            AssetTreeNode atn = new AssetTreeNode(f.Filename, (int)EAssetImageList.Frames, (int)EAssetImageList.Frames, f);

            tvAssets.SelectedNode.Nodes.Add(atn);
            CachedAsset ca = GetCachedAssetForNode(tvAssets.SelectedNode);

            ca.AddAsset(GetRelativePathForNode(atn));
        }
        public string GetTitleForPath(string path)
        {
            CachedAsset ca = CachedAssets.Find(tca => string.Compare(tca.Path, path, true) == 0);

            if (ca != null)
            {
                return(ca.Title);
            }
            else
            {
                return("");
            }
        }
        public string GetPathForTitle(string title)
        {
            CachedAsset ca = CachedAssets.Find(tca => title == tca.Title);

            if (ca != null)
            {
                return(ca.Path);
            }
            else
            {
                return("");
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            foreach (string ptr in PathsToRemove)
            {
                string title = Globals.AppSettings.GetTitleForPath(ptr);
                Globals.AppSettings.RemoveAssetScanPath(ptr);
                Globals.AppForm.RemoveAssetGroupByTitle(title);
            }

            foreach (string ptc in PathsToChange)
            {
                CachedAsset ca = Globals.AppSettings.CachedAssets.Find(tca => tca.Path == ptc);
                for (int i = 0; i < lvASP.Items.Count; i++)
                {
                    if (lvASP.Items[i].SubItems[1].Text == ptc)
                    {
                        Globals.AppForm.ChangeAssetTitle(ca.Title, lvASP.Items[i].Text);
                        ca.Title = lvASP.Items[i].Text;
                    }
                }
            }

            ScanPathForm spf = null;

            foreach (string pta in PathsToAdd)
            {
                if (spf == null)
                {
                    spf = new ScanPathForm();
                }
                for (int i = 0; i < lvASP.Items.Count; i++)
                {
                    if (lvASP.Items[i].SubItems[1].Text == pta)
                    {
                        CachedAsset ca = new CachedAsset();
                        ca.Path  = lvASP.Items[i].SubItems[1].Text;
                        ca.Title = lvASP.Items[i].Text;
                        Globals.AppSettings.CachedAssets.Add(ca);
                        spf.StartScan(ca.Path);
                        Globals.AppForm.AddAssetPath(ca.Title, spf.Found, null);
                        ca.SetAssetsFromFoundList(spf.Found);
                        break;
                    }
                }
            }

            Globals.AppSettings.SaveSettings();

            Close();
        }
        bool GetReadOnlyStatus(TreeNode tn)
        {
            while (tn.Parent != null)
            {
                tn = tn.Parent;
            }
            CachedAsset ca = Globals.AppSettings.CachedAssets.Find(a => a.Title == tn.Text);

            if (ca == null)
            {
                return(true);
            }
            return(ca.IsReadOnly);
        }
        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tvAssets.SelectedNode.Parent == null)
            {
                string title = tvAssets.SelectedNode.Text;
                string path  = Globals.AppSettings.GetPathForTitle(tvAssets.SelectedNode.Text);

                // change this to a proper unload+clear
                TreeNode sn = tvAssets.SelectedNode;
                tvAssets.SelectedNode = null;
                tvAssets.Nodes.Remove(sn);
                CachedAsset ca = Globals.AppSettings.CachedAssets.Find(tca => title == tca.Title);
                if (ca != null)
                {
                    ca.Assets = AddAssetPath(title, path, null);
                }
            }
            else if (tvAssets.SelectedNode.Text.EndsWith(LuaScriptAsset.FileExtension))
            {
            }
            else if (tvAssets.SelectedNode.Text.EndsWith(Animation.FileExtension))
            {
            }
            else if (tvAssets.SelectedNode.Text.EndsWith(Frames.FileExtension))
            {
                // delete the existing asset and load from file
                AssetTreeNode atn = tvAssets.SelectedNode as AssetTreeNode;
                UnsetWorkingFrames();
                atn.Asset = null;
                tvAssets_AfterSelect(tvAssets, new TreeViewEventArgs(atn));
            }
            else
            {
                string      title = tvAssets.SelectedNode.Text;
                string      path  = GetRelativePathForNode(tvAssets.SelectedNode);
                CachedAsset ca    = GetCachedAssetForNode(tvAssets.SelectedNode);

                // change this to a proper unload+clear
                TreeNode sn = tvAssets.SelectedNode;
                TreeNode pn = sn.Parent;
                tvAssets.SelectedNode = null;
                tvAssets.Nodes.Remove(sn);
                int i = ca.Assets.FindIndex(a => a.StartsWith(path));
                ca.Assets.RemoveAll(tca => tca.StartsWith(path + '\\'));
                List <string> foundlist = AddAssetPath(title, ca.Path + path, pn);
                ca.Assets.InsertRange(i, foundlist);
            }
        }
        string GetFullPathForNode(TreeNode tn)
        {
            string path = "";
            string root = "";

            while (tn != null)
            {
                if (tn.Parent == null)
                {
                    path = "\\" + path;
                    root = tn.Text;
                }
                else
                {
                    if (path == "")
                    {
                        path = tn.Text;
                    }
                    else
                    {
                        path = tn.Text + '\\' + path;
                    }
                }

                tn = tn.Parent;
            }

            CachedAsset ca = Globals.AppSettings.CachedAssets.Find(tca => root == tca.Title);

            if (ca != null)
            {
                return(ca.Path + path);
            }
            else
            {
                return("");
            }
        }
        private void tvAssets_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (string.IsNullOrEmpty(e.Label))
            {
                e.CancelEdit = true;
                return;
            }

            AssetTreeNode atn = e.Node as AssetTreeNode;

            // renaming an asset file
            if (atn != null)
            {
                if (((atn.Asset is Frames) && !e.Label.EndsWith(Frames.FileExtension)) ||
                    ((atn.Asset is Animation) && !e.Label.EndsWith(Animation.FileExtension)) ||
                    ((atn.Asset is LuaScriptAsset) && !e.Label.EndsWith(LuaScriptAsset.FileExtension)))
                {
                    MessageBox.Show("The file extension must the file type!", "File extension error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.CancelEdit = true;
                    return;
                }

                if (File.Exists(Path.Combine(atn.Asset.FilePath, e.Label)))
                {
                    MessageBox.Show("The new file name must not already be in use!", "Existing file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.CancelEdit = true;
                    return;
                }

                try
                {
                    if (File.Exists(Path.Combine(atn.Asset.FilePath, atn.Asset.Filename)))
                    {
                        File.Move(Path.Combine(atn.Asset.FilePath, atn.Asset.Filename), Path.Combine(atn.Asset.FilePath, e.Label));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "File rename error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.CancelEdit = true;
                    return;
                }

                CachedAsset ca = GetCachedAssetForNode(e.Node);
                ca.RenameAsset(atn.Asset.Filename, e.Label);
                atn.Asset.Filename = e.Label;
            }
            else
            {
                string dirpath = GetFullPathForNode(e.Node.Parent);

                if (Directory.Exists(Path.Combine(dirpath, e.Label)))
                {
                    MessageBox.Show("The new directory name already exists!", "Existing directory error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.CancelEdit = true;
                    return;
                }

                try
                {
                    Directory.Move(Path.Combine(dirpath, e.Node.Text), Path.Combine(dirpath, e.Label));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "Directory rename error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.CancelEdit = true;
                    return;
                }

                // all assets under this branch need their paths recalculated
                UpdateFilePaths(e.Node, Path.Combine(dirpath, e.Label));
            }
        }