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);
            }
        }
Exemple #2
0
 protected void InvokeMoved(DirItem mover, FolderItem oldParent, FolderItem newParent)
 {
     if (OnMoved != null)
     {
         OnMoved(mover, oldParent, newParent);
     }
     ProjectProperties.CurrentProjectPropperties.Save();
 }
Exemple #3
0
 protected void InvokeRenamed(DirItem sender, string oldName, string newName)
 {
     if (OnRenamed != null)
     {
         OnRenamed(sender, oldName, newName);
     }
     ProjectProperties.CurrentProjectPropperties.Save();
 }
        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);
        }
 internal void RecursivlyCloseOpenFiles(DirItem node)
 {
     if (node is FolderItem)
     {
         foreach (DirItem child in ((FolderItem)node).Children)
         {
             RecursivlyCloseOpenFiles(child);
         }
         return;
     }
     if (node is FileItem)
     {
         FileItem file = (FileItem)node;
         if (file.OpenFile != null)
         {
             file.OpenFile.Editor.Dispose();
             tabStrip.RemoveTab(file.OpenFile.TabPage);
             file.OpenFile.TabPage.Dispose();
             openFiles.Remove(file.OpenFile);
             file.OpenFile = null;
         }
         return;
     }
 }
 private void DeActivate(DirItem item, bool deactivate)
 {
     if (item is FolderItem)
     {
         FolderItem folder = (FolderItem) item;
         if (folder.Parent != null)
             folder.GUINode.ForeColor = deactivate ? Color.Gray : Color.Black;
         foreach (DirItem dirItem in folder.Children)
         {
             DeActivate(dirItem, deactivate);
         }
     }
     if (item is FileItem)
     {
         FileItem file = (FileItem)item;
         if (file.Deactivated != deactivate)
         {
             if (deactivate)
                 compiler.RemoveSourceFile(file);
             else
                 compiler.AddSourceFile(file);
         }
         file.Deactivated = deactivate;
         file.GUINode.ForeColor = deactivate ? Color.Gray : Color.Black;
     }
 }
 protected void InvokeRenamed(DirItem sender, string oldName, string newName)
 {
     if (OnRenamed != null)
         OnRenamed(sender, oldName, newName);
     ProjectProperties.CurrentProjectPropperties.Save();
 }
 protected void InvokeMoved(DirItem mover, FolderItem oldParent, FolderItem newParent)
 {
     if (OnMoved != null)
         OnMoved(mover, oldParent, newParent);
     ProjectProperties.CurrentProjectPropperties.Save();
 }
        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);
            }
        }
        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;
        }