Example #1
0
        public void Import(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            FileStream    stream     = File.Open(path, FileMode.Open);
            XmlSerializer serializer = new XmlSerializer(typeof(FolderSettings));

            _instance = (FolderSettings)serializer.Deserialize(stream);
            stream.Close();
        }
Example #2
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            // Save all png files which have settings referenced to them to a new folder according to the naming convention.
            Dictionary <string, string> fileNames = new Dictionary <string, string>();
            FolderSettings settings = FolderSettings.Instance;

            prbExport.Visible = true;

            for (int i = 0; i < cobAnimations.Items.Count; i++)
            {
                var stripe = (string)cobAnimations.Items[i];

                if (settings.StripeConfigured(stripe))
                {
                    // Create new file name according to the naming convention.
                    fileNames.Add(stripe, settings.GetAnimationName(stripe) + "_frames_" + settings.GetFrames(stripe).ToString() + "_fps_" + settings.GetFramesPerSecond(stripe).ToString());
                }
                else
                {
                    MessageBox.Show("You have to control and configure all animations before you can export them");
                    return;
                }
            }

            // All files are configured - Now save them to new files.

            // Create new folder that contains the images following the naming convention
            string path = Application.StartupPath + "\\SendToBernhard";

            if (Directory.Exists(path))
            {
                // Delete files in directory if already exists.
                DirectoryInfo dirInfo = new DirectoryInfo(path);

                foreach (FileInfo fi in dirInfo.GetFiles())
                {
                    fi.Delete();
                }
            }
            else
            {
                Directory.CreateDirectory(path);
            }

            int totalFiles = fileNames.Count;
            int savedFiles = 0;

            foreach (var pair in fileNames)
            {
                Texture2D texture = Animator.Instance.LoadedTextures[pair.Key];

                // Save to disk
                using (Stream stream = File.OpenWrite(path + "\\" + pair.Value + ".png"))
                {
                    if (stream != null)
                    {
                        texture.SaveAsPng(stream, texture.Width, texture.Height);
                        stream.Close();

                        // Update progress bar.
                        savedFiles++;
                        prbExport.Value = (savedFiles / totalFiles) * 100;
                    }
                }
            }

            // Also save the settings file in the folder
            settings.Export(path + "\\" + SettingsFileName);

            //prbExport.Visible = false;
        }