public override bool MoveTo(FolderItem target, int index)
        {
            //Dont move if a file of same name is there
            bool doMove = target != Parent;
            if (doMove && target.Dir.GetFiles().Any(file => file.Name == Name))
            {
                return false;
            }

            FolderItem oldParent = Parent;
            Parent = target;

            oldParent.Children.Remove(this);
            if (index >= Parent.Children.Count)
                Parent.Children.Add(this);
            else
                Parent.Children.Insert(index, this);

            if (doMove)
            {
                File.Move(oldParent.Dir.FullName + "\\" + Name,
                          Parent.Dir.FullName + "\\" + Name);
            }

            InvokeMoved(this, oldParent, target);

            return true;
        }
 public static List<DialogItem> GetDialogsFiles(FolderItem item)
 {
     List<DialogItem> list = new List<DialogItem>();
     if (item == null) return list;
     foreach (DirItem dirItem in item.Children)
     {
         if (dirItem is FolderItem)
             list.AddRange(GetDialogsFiles((FolderItem)dirItem));
         else if (dirItem is DialogItem)
             list.Add((DialogItem)dirItem);
     }
     return list;
 }
 public FolderItem(FolderItem p, string name)
     : base(p)
 {
     //Dir = dir;
     this.name = name;
     if (!Dir.Exists)
         Dir.Create();
     /*watcher = new FileSystemWatcher(dir.FullName, ".galaxy++");
     watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
     watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
     watcher.EnableRaisingEvents = true;*/
 }
        public override bool MoveTo(FolderItem targetParent, int index)
        {
            //Dont move if it is the main folder
            if (Parent == null)
                return false;

            //Dont move if target is a child of current
            {
                FolderItem t = targetParent;
                while (t != null)
                {
                    if (t == this)
                        return false;
                    t = t.Parent;
                }
            }

            //Dont move if a dir of same name is there
            if (targetParent.Dir.GetDirectories().Any(dir => dir.FullName.TrimEnd('\\', '/') != Dir.FullName.TrimEnd('\\', '/') && dir.Name == Dir.Name))
                return false;

            if (targetParent != Parent)
                Dir.MoveTo(targetParent.Dir.FullName + "\\" + Dir.Name);

            FolderItem oldParent = Parent;
            Parent = targetParent;

            oldParent.Children.Remove(this);
            if (index >= Parent.Children.Count)
                Parent.Children.Add(this);
            else
                Parent.Children.Insert(index, this);

            InvokeMoved(this, oldParent, targetParent);

            return true;
        }
Ejemplo n.º 5
0
        private static void CopyFiles(DirItem item, FolderItem outputDir, FileInfo rootFile, DirectoryInfo targetDir)
        {
            if (item is FolderItem)
            {
                FolderItem dir = (FolderItem)item;
                DirectoryInfo childDir = dir == outputDir ? targetDir : targetDir.CreateSubdirectory(dir.Text);
                foreach (DirItem nextItem in dir.Children)
                {
                    CopyFiles(nextItem, outputDir, rootFile, childDir);
                }
            }
            if (item is FileItem)
            {
                FileItem file = (FileItem)item;
                string fileName = file.File.Name;
                if (file.File.FullName == rootFile.FullName)
                    fileName = "MapScript.galaxy";
                else if (fileName.ToLower() == "mapscript.galaxy")
                {
                    MessageBox.Show(LocRM.GetString("ME_Text2"), LocRM.GetString("ALL_Error"));
                    return;
                }

                file.File.CopyTo(Path.Combine(targetDir.FullName, fileName), true);
            }
        }
 public FileItem(FolderItem p, string name)
     : base(p)
 {
     //File = file;
     this.name = name;
     if (!File.Exists)
         File.Create().Close();
 }
 public abstract bool MoveTo(FolderItem target, int index);
Ejemplo n.º 8
0
        private void AddNodes(FolderItem dir)
        {
            //dir is a good enough representation of what is on hdd.. just use that tree

            foreach (DirItem dirItem in dir.Children)
            {
                dirItem.GUINode = new TreeNode(dirItem.Text);
                dirItem.GUINode.Tag = dirItem;
                dirItem.GUINode.SelectedImageIndex =
                    dirItem.GUINode.ImageIndex = dirItem is FolderItem
                                                     ? 1
                                                     : dirItem.Text.EndsWith(".xml")
                                                           ? 3
                                                           : dirItem is DialogItem ? 5 : 2;
                dirItem.GUINode.ForeColor = Color.Black;
                dir.GUINode.Nodes.Add(dirItem.GUINode);
                if (dirItem is FileItem)
                {
                    FileItem fileItem = (FileItem)dirItem;
                    if (fileItem.Deactivated)
                        dirItem.GUINode.ForeColor = Color.Gray;
                }
                if (dirItem is FolderItem)
                {
                    FolderItem folderItem = (FolderItem) dirItem;
                    AddNodes(folderItem);

                    if (!folderItem.Children.Any(child => child.GUINode.ForeColor == Color.Black))
                        dirItem.GUINode.ForeColor = Color.Gray;
                }
                if (dirItem is DialogItem)
                {
                    DialogItem item = (DialogItem) dirItem;
                    item.CodeGUINode = new TreeNode(item.Name.Substring(0, item.Name.LastIndexOf(".Dialog")) + ".galaxy++");
                    item.CodeGUINode.SelectedImageIndex = item.CodeGUINode.ImageIndex = 2;
                    item.CodeGUINode.Tag = item;
                    item.GUINode.Nodes.Add(item.CodeGUINode);

                    item.DesignerGUINode = new TreeNode(item.Name.Substring(0, item.Name.LastIndexOf(".Dialog")) + ".Designer.galaxy++");
                    item.DesignerGUINode.SelectedImageIndex = item.DesignerGUINode.ImageIndex = 2;
                    item.DesignerGUINode.Tag = item;
                    item.GUINode.Nodes.Add(item.DesignerGUINode);

                }
            }
            if (dir.Expanded)
                dir.GUINode.Expand();
            else
                dir.GUINode.Collapse();
        }
 protected DirItem(FolderItem p)
 {
     Parent = p;
 }
 public bool IsDecendantOf(FolderItem folder)
 {
     if (this == folder)
         return true;
     if (Parent == null)
         return false;
     return Parent.IsDecendantOf(folder);
 }
Ejemplo n.º 11
0
 public DialogItem(FolderItem p) : base(p)
 {
 }
Ejemplo n.º 12
0
 public abstract bool MoveTo(FolderItem target, int index);
Ejemplo n.º 13
0
 protected DirItem(FolderItem p)
 {
     Parent = p;
 }
Ejemplo n.º 14
0
        private void newFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Make new folder
            TreeNode folderNode = projectView.SelectedNode ?? ProjectProperties.CurrentProjectPropperties.SrcFolder.GUINode;

            DirItem markedChild = (DirItem) folderNode.Tag;
            FolderItem parentFolder = (FolderItem) (markedChild.Parent ?? markedChild);
            if (markedChild is FolderItem)
                parentFolder = (FolderItem) markedChild;

            string name = "New folder";
            int i = 1;
            while (parentFolder.Children.Any(child => child.Text == name))
            {
                i++;
                name = "New folder" + i;
            }

            FolderItem newFolder = new FolderItem(parentFolder, name);

            newFolder.GUINode = new TreeNode(name);

            newFolder.GUINode.Tag = newFolder;
            newFolder.GUINode.ImageIndex = newFolder.GUINode.SelectedImageIndex = 1;

            //Insert into tree
            int insertAt = parentFolder.Children.IndexOf(markedChild) + 1;
            if (insertAt == 0 || insertAt == parentFolder.Children.Count)
            {
                parentFolder.Children.Add(newFolder);
                parentFolder.GUINode.Nodes.Add(newFolder.GUINode);
            }
            else
            {
                parentFolder.Children.Insert(insertAt, newFolder);
                parentFolder.GUINode.Nodes.Insert(insertAt, newFolder.GUINode);
            }
            ProjectProperties.CurrentProjectPropperties.Save();

            projectView.SelectedNode = newFolder.GUINode;
            newFolder.GUINode.EnsureVisible();
            BeginRename(newFolder.GUINode);
        }
 protected void InvokeMoved(DirItem mover, FolderItem oldParent, FolderItem newParent)
 {
     if (OnMoved != null)
         OnMoved(mover, oldParent, newParent);
     ProjectProperties.CurrentProjectPropperties.Save();
 }
Ejemplo n.º 16
0
 public static List<FileItem> GetSourceFiles(FolderItem item)
 {
     List<FileItem> list = new List<FileItem>();
     if (item == null) return list;
     foreach (DirItem dirItem in item.Children)
     {
         if (dirItem is FolderItem)
             list.AddRange(GetSourceFiles((FolderItem) dirItem));
         else if (dirItem is FileItem && !((FileItem)dirItem).Deactivated)
             list.Add((FileItem) dirItem);
     }
     return list;
 }
 public DialogItem(FolderItem p)
     : base(p)
 {
 }
Ejemplo n.º 18
0
        private static bool CopyFiles(DirItem item, FolderItem outputDir, FileInfo rootFile, UInt32 mpqHandle)
        {
            bool success = true;

            if (item is FolderItem)
            {
                FolderItem dir = (FolderItem)item;
                foreach (DirItem nextItem in dir.Children)
                {
                    success &= CopyFiles(nextItem, outputDir, rootFile, mpqHandle);
                }
            }
            if (item is FileItem)
            {
                FileItem file     = (FileItem)item;
                string   fileName = file.File.FullName.Remove(0, outputDir.Dir.FullName.Length + 1);
                if (file.File.FullName == rootFile.FullName)
                {
                    fileName = "MapScript.galaxy";
                }
                else if (fileName.ToLower() == "mapscript.galaxy")
                {
                    MessageBox.Show(LocRM.GetString("ME_Text2"), LocRM.GetString("ALL_Error"));
                    return(false);
                }
                List <byte> byteList = new List <byte>();
                Stream      stream   = file.File.OpenRead();
                int         b;
                while ((b = stream.ReadByte()) != -1)
                {
                    byteList.Add((byte)b);
                }
                byte[] bytes            = byteList.ToArray();
                IntPtr unmanagedPointer = Marshal.AllocHGlobal(bytes.Length);
                Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length);
                // Call unmanaged code
                // byte[] bytes = ToByteArray(stream.ReadToEnd());

                /*StreamReader stream = file.OpenText();
                 * UTF8Encoding encoding = new System.Text.UTF8Encoding();
                 * byte[] bytes = encoding.GetBytes(stream.ReadToEnd());*/
                stream.Close();



                UInt32 fileHandle = 0;
                bool   fSuccess   = SFileCreateFile(mpqHandle, ToByteArray(fileName), (ulong)DateTime.Now.Ticks, (uint)bytes.Length, 0, 0x200, ref fileHandle);
                if (fSuccess)
                {
                    fSuccess = SFileWriteFile(fileHandle, unmanagedPointer, (uint)bytes.Length, 0x12);
                }
                if (fSuccess)
                {
                    fSuccess = SFileFinishFile(fileHandle);
                }

                if (!fSuccess)
                {
                    MessageBox.Show(LocRM.GetString("ME_Text3") + fileName + LocRM.GetString("ME_Text4"), LocRM.GetString("ALL_Error"));
                }

                success &= fSuccess;
                Marshal.FreeHGlobal(unmanagedPointer);
            }
            return(success);
        }
Ejemplo n.º 19
0
        private static bool CopyFiles(DirItem item, FolderItem outputDir, FileInfo rootFile, UInt32 mpqHandle)
        {
            bool success = true;
            if (item is FolderItem)
            {
                FolderItem dir = (FolderItem)item;
                foreach (DirItem nextItem in dir.Children)
                {
                    success &= CopyFiles(nextItem, outputDir, rootFile, mpqHandle);
                }
            }
            if (item is FileItem)
            {
                FileItem file = (FileItem)item;
                string fileName = file.File.FullName.Remove(0, outputDir.Dir.FullName.Length + 1);
                if (file.File.FullName == rootFile.FullName)
                    fileName = "MapScript.galaxy";
                else if (fileName.ToLower() == "mapscript.galaxy")
                {
                    MessageBox.Show(LocRM.GetString("ME_Text2"), LocRM.GetString("ALL_Error"));
                    return false;
                }
                List<byte> byteList = new List<byte>();
                Stream stream = file.File.OpenRead();
                int b;
                while ((b = stream.ReadByte()) != -1)
                {
                    byteList.Add((byte) b);
                }
                byte[] bytes = byteList.ToArray();
                IntPtr unmanagedPointer = Marshal.AllocHGlobal(bytes.Length);
                Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length);
                // Call unmanaged code
               // byte[] bytes = ToByteArray(stream.ReadToEnd());
                /*StreamReader stream = file.OpenText();
                UTF8Encoding encoding = new System.Text.UTF8Encoding();
                byte[] bytes = encoding.GetBytes(stream.ReadToEnd());*/
                stream.Close();

                UInt32 fileHandle = 0;
                bool fSuccess = SFileCreateFile(mpqHandle, ToByteArray(fileName), (ulong)DateTime.Now.Ticks, (uint)bytes.Length, 0, 0x200, ref fileHandle);
                if (fSuccess)
                    fSuccess = SFileWriteFile(fileHandle, unmanagedPointer, (uint)bytes.Length, 0x12);
                if (fSuccess)
                    fSuccess = SFileFinishFile(fileHandle);

                if (!fSuccess)
                {
                    MessageBox.Show(LocRM.GetString("ME_Text3") + fileName + LocRM.GetString("ME_Text4"), LocRM.GetString("ALL_Error"));
                }

                success &= fSuccess;
                Marshal.FreeHGlobal(unmanagedPointer);

            }
            return success;
        }