private void Save()
{
this.Cursor = Cursors.WaitCursor;
this.Size = _lastSize;
this.Invalidate();
Application.DoEvents();
if (!Settings.Default.saveLocation) // to choose the location to save the gif
{
#region If Not Save Directly to the Desktop
var sfd = new SaveFileDialog();
sfd.Filter = "GIF file (*.gif)|*gif";
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
sfd.DefaultExt = "gif";
this.Cursor = Cursors.Default;
if (sfd.ShowDialog() == DialogResult.OK)
{
_outputpath = sfd.FileName;
_workerThread = new Thread(DoWork);
_workerThread.IsBackground = true;
_workerThread.Name = "Gif Encoding";
_workerThread.Start();
}
else //if user don't want to save the gif
{
FinishState();
btnRecordPause.Text = Resources.btnRecordPause_Record;
btnRecordPause.Image = Resources.Record;
btnRecordPause.ImageAlign = ContentAlignment.MiddleLeft;
this.Text = Resources.TitleStoped;
AutoFitButtons();
this.Invalidate();
try
{
//_actHook.KeyDown += KeyHookTarget;
_actHook.OnMouseActivity += null;
_actHook.Start(false, true);
}
catch (Exception) { }
Directory.Delete(_pathTemp, true);
}
#endregion
}
else
{
#region Search For Filename
bool searchForName = true;
int numOfFile = 0;
string path;
//If there is no defined save location, saves in the desktop.
if (String.IsNullOrEmpty(Settings.Default.folder))
{
path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
}
else
{
path = Settings.Default.folder;
}
this.Cursor = Cursors.Default;
#region Ask if should encode
DialogResult ask = MessageBox.Show(this, Resources.Msg_WantEncodeAnimation + path, "Screen To Gif",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
//Only saves the recording if the user wants to.
if (ask != DialogResult.Yes)
{
//If the user don't want to save the recording.
this.Text = Resources.TitleStoped;
#region Clear Variables
_listFrames.Clear();
_listDelay.Clear();
//These variables are only used in the editor.
if (_listFramesEdit != null)
{
_listFramesEdit.Clear();
_listFramesUndo.Clear();
_listDelayEdit.Clear();
_listDelayUndo.Clear();
}
GC.Collect();
#endregion
Directory.Delete(_pathTemp, true);
FinishState();
try
{
//Restart the keyhook.
//_actHook.KeyDown += KeyHookTarget;
_actHook.Start(false, true);
}
catch (Exception) { }
return;
}
#endregion
#region FileName
while (searchForName)
{
if (!File.Exists(path + "\\Animation " + numOfFile + ".gif"))
{
_outputpath = path + "\\Animation " + numOfFile + ".gif";
searchForName = false;
}
else
{
if (numOfFile > 999)
{
searchForName = false;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
_outputpath = saveFileDialog.FileName;
}
else
{
_outputpath = "No filename for you.gif";
}
}
numOfFile++;
}
}
#endregion
#endregion
_workerThread = new Thread(DoWork);
_workerThread.IsBackground = true;
_workerThread.Name = "Gif Encoding";
_workerThread.Start();
}
//FinishState();
}