Esempio n. 1
0
        public static void ExeSlotAction(int id, string[] registryData)
        {
            string[] itemValues = GetDataFromId(registryData, id);
            string   title      = itemValues[0];
            string   path       = itemValues[1];
            string   args       = itemValues[2];

            if (File.Exists(path) || Directory.Exists(path) || path.StartsWith("http"))
            {
                Framework.Log("Valid file, directory or URL, beginning process launch");
                var process = Process.Start(path, args);

                if (args != null && args != "")
                {
                    Framework.Log("Process " + path + " launched with " + args);
                }
                else
                {
                    Framework.Log("Process " + path + " launched");
                }
            }
            else
            {
                Framework.ShowError("The specified file or directory " + path + " don't exist");
            }
        }
Esempio n. 2
0
        public string ProcessFinalPath(string trueFilePath)
        {
            if (m_inputPath != null)
            {
                m_customTempFile = m_inputPath + @"\" + Path.GetFileName(trueFilePath);

                if (Directory.Exists(m_inputPath))
                {
                    File.Copy(trueFilePath, m_customTempFile);
                    Framework.Log("(Custom path) file copied to: " + m_customTempFile);

                    m_inputPath = trueFilePath;

                    return(m_customTempFile);
                }
                else
                {
                    Framework.ShowError("Unable to access to the specified path", true);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
        private bool MagickConvert()
        {
            try
            {
                using (MagickImage image = new MagickImage(m_filePath))
                {
                    //Use PNG if the image have an alpha channel
                    if (image.HasAlpha)
                    {
                        m_tempFilePath = Path.GetDirectoryName(m_filePath) + @"\" + Path.GetFileNameWithoutExtension(m_filePath) + ".png";
                        Framework.Log("Alpha channel found, using PNG");
                    }
                    else
                    {
                        m_tempFilePath = Path.GetDirectoryName(m_filePath) + @"\" + Path.GetFileNameWithoutExtension(m_filePath) + ".bmp";
                    }

                    image.Write(m_tempFilePath);

                    Framework.Log("(Magick) Temporary image saved: " + m_tempFilePath);
                }
                return(true);
            }
            catch (InvalidCastException e)
            {
                Framework.ShowError("Unable to save the temporary image at: " + m_tempFilePath);
                return(false);
            }
        }
        public static string GetCRYENGINELocation()
        {
            if (Framework.cryengineLocation == null)
            {
                string value = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Crytek\Settings", "ENG_RootPath", null);
                if (value != null)
                {
                    if (!Directory.Exists(value))
                    {
                        Framework.ShowError("The CRYENGINE path from the registry not exist (try to use the Settings Manager)", true);
                        return(null);
                    }
                    else
                    {
                        Framework.cryengineLocation = value + @"\";

                        Framework.Log("CRYENGINE path find at: " + value);
                        return(value + @"\");
                    }
                }
                else
                {
                    ShowError("Unable to find the CRYENGINE path from the registry (try to use the Settings Manager)", true);
                    return(null);
                }
            }
            else
            {
                return(Framework.cryengineLocation);
            }
        }
Esempio n. 5
0
        //Browse files functions
        private void browseFilesButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Title       = "Open textures or meshes";
            dialog.Filter      = "Textures and Meshes|*.tif; *.jpg; *.png; *.bmp; *.fbx; *.dae; *.tga; *.psd"; //Supported files
            dialog.Multiselect = true;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string[] files = dialog.FileNames;
                    foreach (string file in files)
                    {
                        if (file != null)
                        {
                            Framework.Log("File selected from dialog: " + file);
                            Framework.BeginImport(file, m_customOutput);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Framework.ShowError("Cannot read the file from the disk");
                }
            }
        }
        public static void CRYENGINE_RC_Call(string commands, string logWhenFinished = null)
        {
            string rcPathBin32 = GetCRYENGINELocation() + @"Bin32\RC\rc.exe";
            string rcPathBin64 = GetCRYENGINELocation() + @"Bin64\RC\rc.exe";
            string rcPath;

            //If found, use the 64 bits Ressource Compiler
            if (File.Exists(rcPathBin64))
            {
                rcPath = rcPathBin64;
            }
            else
            {
                rcPath = rcPathBin32;
            }

            if (File.Exists(rcPath))
            {
                #if DEBUG
                //commands = commands + " /wait";
                #endif

                Framework.Log("Beginning RC call: " + commands);

                Process process = new Process();
                process.StartInfo.FileName  = rcPath;
                process.StartInfo.Arguments = commands;
                //process.StartInfo.RedirectStandardOutput = true;

                #if !DEBUG
                process.StartInfo.CreateNoWindow  = true;
                process.StartInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                process.StartInfo.UseShellExecute = false;
                #endif

                process.Start();
                Framework.Log("RC call send");

                process.WaitForExit();
                Framework.Log("RC terminated");

                if (logWhenFinished != null)
                {
                    Framework.Log(logWhenFinished);
                }
            }
            else
            {
                Framework.ShowError("Unable to find RC.exe", true);
            }
        }
        public static void BeginImport(string filePath, string customPath)
        {
            //Custom path support
            CCustomPath customPathObj = new CCustomPath(customPath);

            if (customPath != null && customPath != "")
            {
                string tPath = customPathObj.ProcessFinalPath(filePath);
                if (tPath != null)
                {
                    filePath = tPath;
                }
            }


            switch (GetConversionType(filePath))
            {
            case "texture":
                new CTextureTiffConvert(filePath);
                break;

            case "texture_magick":
                new CTextureMagick(filePath);
                break;

            case "mesh":
                Framework.CRYENGINE_RC_Call(filePath + " /refresh");

                string newFilePath = Path.GetDirectoryName(filePath) + @"\" + Path.GetFileNameWithoutExtension(filePath) + ".cgf";
                if (File.Exists(newFilePath))
                {
                    Framework.Log("File " + Path.GetFileName(filePath) + " succefully send to the Ressource Compiler at " + newFilePath);
                }
                else
                {
                    Framework.ShowError("The Resource Compiler was unable to process the file. Check rc_log.log for more details.");
                }

                break;
            }

            //Custom path call delete temp file
            if (customPath != null)
            {
                customPathObj.DeleteTempFile();
            }
        }
        public CTextureMagick(string filePath)
        {
            m_filePath = filePath;
            m_fileName = Path.GetFileName(filePath);

            if (!File.Exists("Magick.NET-x64.dll"))
            {
                Framework.ShowError("Unable to find Magick.NET-x64.dll", true);
            }

            Framework.Log("ImageMagick library loaded, beginning conversion");

            if (MagickConvert())
            {
                new CTextureTiffConvert(m_tempFilePath);
                DeleteTempFile();
            }
        }
        public CTextureFromClipboard(string dialogPath, string customPath, Image clipboardData)
        {
            //Allow filepaths with and without extensions
            if (Path.GetExtension(dialogPath) != "")
            {
                m_tempFilePath = Path.GetDirectoryName(dialogPath) + @"\" + Path.GetFileNameWithoutExtension(dialogPath) + ".bmp";
            }
            else
            {
                m_tempFilePath = dialogPath + ".bmp";
            }


            if (SaveTempBitmap(clipboardData))
            {
                new CTextureTiffConvert(m_tempFilePath);
                deleteTempFile();
            }
            else
            {
                Framework.ShowError("Unable to save the temporary file due to clipboard conversion");
            }
        }
        public void Convert()
        {
            try
            {
                BitmapDecoder bmpDec = BitmapDecoder.Create(new Uri(m_filePath), BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
                BitmapSource  srs    = bmpDec.Frames[0];

                if (Path.GetExtension(m_convertedFilePath).Equals(".tif", StringComparison.CurrentCultureIgnoreCase))
                {
                    using (FileStream stream = new FileStream(m_convertedFilePath, FileMode.Create, FileAccess.Write, FileShare.Delete))
                    {
                        TiffBitmapEncoder encoder = new TiffBitmapEncoder();
                        encoder.Compression = TiffCompressOption.None;
                        encoder.Frames.Add(BitmapFrame.Create(srs));
                        encoder.Save(stream);
                    }
                }
            }
            catch (Exception ex)
            {
                Framework.ShowError("Unable to save the temporary file at: " + m_convertedFilePath, true);
            }
        }