Ejemplo n.º 1
0
        private static void ListContents(string maxFileName)
        {
            ARMaxNativeMethods.InitMaxSave();
            ARMaxNativeMethods.LoadSave(maxFileName);
            StringBuilder buff     = new StringBuilder(256);
            int           numFiles = ARMaxNativeMethods.NumberOfFiles();
            int           fileSize = -1;
            int           result   = 0;

            Console.WriteLine("Listing contents of {0}:", maxFileName);
            for (int i = 1; i < numFiles + 1; i++) // there is no 0th file
            {
                try
                {
                    result = ARMaxNativeMethods.FileDetails(i, buff, 256, ref fileSize);
                    Console.WriteLine(buff.ToString());
                }
                catch (Exception exc)
                {
                    Console.Error.WriteLine("Error calling 'ARMaxNativeMethods.FileDetails({0})' LastError:{1}",
                                            i, Marshal.GetLastWin32Error());
                }
                buff.Length = 0;
            }
            ARMaxNativeMethods.FreeMaxSave();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds/replaces file in save.
        /// </summary>
        private static void AddFileToSave(string maxFileName, string fileToAdd)
        {
            if (File.Exists(fileToAdd))
            {
                int result = -1;
                ARMaxNativeMethods.InitMaxSave();
                ARMaxNativeMethods.LoadSave(maxFileName);

                int    lastSlash = fileToAdd.LastIndexOf('\\') + 1;
                string shortName = fileToAdd.Substring(lastSlash);

                result = ARMaxNativeMethods.FileExistsInSavePos(shortName);
                if (result > 0)
                {
                    result = ARMaxNativeMethods.ReplaceFileInSave(shortName, fileToAdd);
                }
                else
                {
                    result = ARMaxNativeMethods.AddFileToSave(fileToAdd);
                }

                ARMaxNativeMethods.SaveMaxFile(maxFileName);
                ARMaxNativeMethods.FreeMaxSave();
                Console.WriteLine("Added file '{0}' to save '{1}'.", shortName, maxFileName);
            }
            else
            {
                Console.WriteLine("File '{0}' does not exist", fileToAdd);
            }
        }
Ejemplo n.º 3
0
        private static void RemoveFileFromSave(string maxFileName, string fileToRemove)
        {
            ARMaxNativeMethods.InitMaxSave();
            ARMaxNativeMethods.LoadSave(maxFileName);

            int result = ARMaxNativeMethods.FileExistsInSavePos(fileToRemove);

            if (result > 0)
            {
                ARMaxNativeMethods.DeleteFileInSave(result);
                ARMaxNativeMethods.SaveMaxFile(maxFileName);
                Console.WriteLine("Removed '{0}' from save file '{1}'", fileToRemove, maxFileName);
            }
            ARMaxNativeMethods.FreeMaxSave();
        }
Ejemplo n.º 4
0
        private static void ExtractSaveContents(string maxFileName, string folderName)
        {
            if (!Directory.Exists(folderName))
            {
                Directory.CreateDirectory(folderName);
            }

            if (!folderName.EndsWith("\\"))
            {
                folderName += "\\";
            }

            ARMaxNativeMethods.InitMaxSave();
            ARMaxNativeMethods.LoadSave(maxFileName);
            StringBuilder buff     = new StringBuilder(256);
            int           result   = -1;
            int           numFiles = ARMaxNativeMethods.NumberOfFiles();

            for (int i = 1; i <= numFiles; i++) // there is no '0'th file
            {
                try
                {
                    result = ARMaxNativeMethods.ExtractAFile(i, folderName);
                    if (result != 0)
                    {
                        Console.Write("'ARMaxNativeMethods.ExtractAFile' Failed; code = {0}", result);
                    }
                }
                catch (Exception exc)
                {
                    Console.Error.WriteLine("Error calling 'ARMaxNativeMethods.GetRootDir()' LastError:{0}\n{1}",
                                            System.Runtime.InteropServices.Marshal.GetLastWin32Error(), exc.Message);
                }
            }
            ARMaxNativeMethods.FreeMaxSave();
            Console.WriteLine("Extracted contents to folder '{0}'", folderName);
        }