Пример #1
1
        //Secondary thread methods
        private void xbt_convert(object selectedPaths)
        {
            //Setup
            string[] files = (string[])selectedPaths;
            Invoke(new setlblTextCallBack(setlblProgressText), "Generating filelist...");

            //Call back to main and grab all the file locations, update progress bar
            /*for (int init = 0; init < files.Length; init++)
            {
                files[init] = (string)Invoke(new CheckedItemCallBack(ReturnListViewItem), init);
                Invoke(new progressCallBack(setProgressBarVal), init);
                Thread.Sleep(1);
            }*/

            //Reset progress bar and do some more setup
            Invoke(new progressCallBack(setProgressBarVal), 0);
            int progress = 0;
            int total = files.Length;

            //Backup the directory if the user set the option
            if (settingsBackup)
            {
                Invoke(new setlblTextCallBack(setlblProgressText), "Creating backup...");
                BackupRootDir(root_dir);
            }

            //Reset progress bar
            Invoke(new progressCallBack(setProgressBarVal), 0);

            //Generate new directory structure if user set option
            if (b_dir_struct)
            {
                Invoke(new setlblTextCallBack(setlblProgressText), "Generating destination directories...");
                BuildDestinationDir(s_dir);
            }

            //Reset progress bar and update label text
            Invoke(new progressCallBack(setProgressBarVal), 0);
            Invoke(new setlblTextCallBack(setlblProgressText), "0/" + total + " textures converted");

            for (progress = 0; progress < total; progress++)
            {
                //Grab the full directory and filename, change the extension
                String fs_out_loc = Path.ChangeExtension(files[progress], ".dds");

                //If the output directory isn't the same as the root dir
                if (b_dir)
                {
                    //Directory structure retained
                    if (b_dir_struct)
                    {
                        fs_out_loc = fs_out_loc.Replace(root_dir, s_dir);
                    }

                    //Everything in one folder
                    else
                    {
                        //Some files have duplicate names
                        if (File.Exists(s_dir + "\\" + Path.GetFileName(fs_out_loc)))
                        {
                            //add a number to the end of the filename
            #warning "Change number when filename changes"
                            fs_out_loc = s_dir + "\\" + Path.GetFileNameWithoutExtension(fs_out_loc) + "_" + duplicateNumber + ".dds";
                            duplicateNumber++;
                        }

                        else
                        {
                            fs_out_loc = s_dir + "\\" + Path.GetFileName(fs_out_loc);
                        }

                    }
                }

                //Finally start converting
                XBT xbt = new XBT(files[progress]);

                //Write output to file
                FileStream fs_out = new FileStream(fs_out_loc, FileMode.Create, FileAccess.Write);
                BinaryWriter writer = new BinaryWriter(fs_out);
                writer.Write(xbt.Texture);

                //Do some cleanup
                writer.Close();
                fs_out.Close();

                //Progress Bar gets updated
                int i_progresslbl = progress + 1;
                Invoke(new progressCallBack(setProgressBarVal), i_progresslbl);
                Invoke(new setlblTextCallBack(setlblProgressText), i_progresslbl + "/" + total + " textures converted");

                //Now that there are no handles on the file, delete the original if the user wants to
                if (settingsDeleteOrig)
                {
                    File.Delete(files[progress]);
                }
            }

            //Restore UI functionality
            Invoke(new completedCallBack(resetUI));
        }
Пример #2
0
        private static int Main(string[] args)
        {
            Console.WriteLine("xbtCMD made by Robert Rouhani");
            Console.WriteLine("Version 0.1");
            System.Threading.Thread.Sleep(1000);

            //make sure there's only 2 args
            if (args.Length != 2)
            {
                Console.WriteLine("Error: Invalid Arguements.");
                WriteHelp();
                return 1;
            }

            //set the args to the location and the destination
            s_location = args[0].ToString();
            s_destination = args[1].ToString();

            //Set the last char for the / check
            s_location_last = s_location.Substring(s_location.Length - 1, 1);
            s_destination_last = s_destination.Substring(s_destination.Length - 1, 1);

            //check for ending with / and fix if it doesn't
            if (s_location_last != "\\" && s_location_last != "/")
            {
                s_location = s_location + "\\";
            }

            if (s_destination_last != "\\" && s_destination_last != "/")
            {
                s_destination = s_destination + "\\";
            }

            //If the location is a file, there are no containing files. Return an error.
            if (File.Exists(s_location))
            {
                Console.WriteLine("{0} is a file, not a directory.", s_location);
                WriteHelp();
                return 1;
            }

            //If the destination is a file, there is no place to put the converted textures. Return an error.
            if (File.Exists(s_destination))
            {
                Console.WriteLine("{0} is a file, not a directory.", s_destination);
                WriteHelp();
                return 1;
            }

            //If the location doesn't exist, there are no files. Return an error.
            if (!Directory.Exists(s_location))
            {
                Console.WriteLine("{0} does not exist.", s_location);
                WriteHelp();
                return 1;
            }

            //Create a destination directory if one doesn't exist.
            if (!Directory.Exists(s_destination))
            {
                Directory.CreateDirectory(s_destination);
            }

            //Build a list of files and generate the directory tree in the destination
            BuildDestinationTree(s_location);
            BuildConvertList(s_location);

            foreach (string file in files)
            {
                XBT XBT = new XBT(file);
                Console.WriteLine("Converting File: {0}", file);

                //Change the destination filename
                string file_dest = file.Replace(s_location, s_destination + "\\");
                file_dest = file_dest.Remove(file_dest.Length - 3, 3);
                file_dest = file_dest + "dds";

                //Write the converted texture to the new file
                FileStream fs_out = new FileStream(@file_dest, FileMode.Create, FileAccess.Write);
                BinaryWriter writer = new BinaryWriter(fs_out);
                writer.Write(XBT.Texture);

                //Cleaning up
                writer.Close();
                fs_out.Close();
            }

            Console.WriteLine("");
            Console.WriteLine("{0} files successfully converted!", files.Count);
            return 0;
        }