in Office365APIEditor/Program.cs [66:232]
static void Main(string[] args)
{
// Save the contents of the log temporarily until the initialization of the setting is completed.
StringBuilder startupLog = new StringBuilder();
startupLog.AppendLine("Start.");
// Load previous settings.
// Default value of NeedUpgrade is TRUE.
// If NeedUpgrade is TRUE, it means that the application has been upgraded.
bool needUpgrade = Properties.Settings.Default.NeedUpgrade;
if (needUpgrade == true)
{
startupLog.AppendLine("Setting upgrade is required.");
try
{
Properties.Settings.Default.Upgrade();
startupLog.AppendLine("Previous setting was loaded.");
UpgradeLastApps(startupLog);
}
catch
{
startupLog.AppendLine("Setting was not upgraded.");
}
finally
{
Properties.Settings.Default.NeedUpgrade = false;
Properties.Settings.Default.Save();
startupLog.AppendLine("Setting was saved.");
}
}
// Turn off SystemLogging flag.
startupLog.AppendLine("Disable SystemLogging as default.");
Properties.Settings.Default.SystemLogging = false;
Properties.Settings.Default.Save();
// Check the command line switches.
startupLog.AppendLine("CommandLine : " + Environment.CommandLine);
string[] switches = Environment.GetCommandLineArgs();
bool systemLogging = false;
foreach (string command in switches)
{
if (command.ToLower() == ("/ResetSettings").ToLower())
{
// Reset all settings.
startupLog.AppendLine("Setting will be reset.");
Properties.Settings.Default.Reset();
Properties.Settings.Default.Save();
startupLog.AppendLine("Setting was saved.");
}
else if(command.ToLower() == ("/RemoveHistory").ToLower())
{
// Remove Run History file.
startupLog.AppendLine("The history file will be delete.");
if (File.Exists(Util.RunHistoryPath))
{
try
{
File.Delete(Util.RunHistoryPath);
startupLog.AppendLine("The history file was deleted.");
}
catch(Exception ex)
{
startupLog.AppendLine("The history file was not deleted.");
MessageBox.Show(ex.Message.ToString(), "Office365APIEditor");
}
}
else
{
startupLog.AppendLine("The history file does not exist.");
}
}
else if (command.ToLower() == ("/ResetCustomDefinedScopes").ToLower())
{
// Reset CustomDefinedScopes setting.
startupLog.AppendLine("CustomDefinedScopes will be reset.");
Properties.Settings.Default.CustomDefinedScopes = null;
Properties.Settings.Default.Save();
startupLog.AppendLine("CustomDefinedScopes setting was saved.");
}
else if (command.ToLower() == ("/EnableSystemLogging").ToLower())
{
// Turn on SystemLogging flag later.
systemLogging = true;
}
}
if (systemLogging)
{
// Turn on SystemLogging flag.
startupLog.AppendLine("Enable SystemLogging.");
Properties.Settings.Default.SystemLogging = true;
Properties.Settings.Default.Save();
}
// Set default log folder path.
startupLog.AppendLine("Current log folder : " + Properties.Settings.Default.LogFolderPath);
if (!Directory.Exists(Properties.Settings.Default.LogFolderPath))
{
startupLog.AppendLine("The log folder does not exist and will be reset.");
Properties.Settings.Default.LogFolderPath = Util.DefaultApplicationPath;
Properties.Settings.Default.Save();
startupLog.AppendLine("New log folder : "+ Properties.Settings.Default.LogFolderPath);
startupLog.AppendLine("Setting was saved.");
}
// Write startup log.
Util.WriteSystemLog("Office365APIEditor startup log", startupLog.ToString());
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Create the MyApplicationContext, that derives from ApplicationContext,
// that manages when the application should exit.
MyApplicationContext context = new MyApplicationContext();
// Start checking the latest version, and download the latest installer if it is available
StartLatestVersionCheck();
// Run the application with the specific context. It will exit when
// all forms are closed.
try
{
Application.Run(context);
}
catch (Exception ex)
{
// Write error log.
try
{
string filePath = Path.Combine(Util.DefaultApplicationPath, "Error.txt");
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.WriteLine(
"Date :" + DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss") + Environment.NewLine +
"Message :" + ex.Message + Environment.NewLine +
"StackTrace :" + ex.StackTrace + Environment.NewLine +
"-----------------------------------------------------------------------------" + Environment.NewLine
);
}
}
catch
{
}
if (ex.InnerException == null)
{
MessageBox.Show(ex.Message, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show(ex.InnerException.Message, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
finally
{
Util.WriteSystemLog("Office365APIEditor Closing Log", "Exit. Code 10");
}
}