我有一个很好的小作业组织者,我想添加备份选项。但是我不想使用普通的xml文件或其他文件,因为文件可能会损坏。那么我该如何创建程序知道并能够保存和打开的文件扩展名.asog?
我有一个很好的小作业组织者,我想添加备份选项。但是我不想使用普通的xml文件或其他文件,因为文件可能会损坏。那么我该如何创建程序知道并能够保存和打开的文件扩展名.asog?
只需在iss文件中添加以下指令:
[Setup]
ChangesAssociations=yes
[Registry]
Root: HKCR; Subkey: ".magi"; ValueType: string; ValueName: ""; ValueData: "MyMAGIApplication"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "MyMAGIApplication"; ValueType: string; ValueName: ""; ValueData: "Program MAGI"; Flags: uninsdeletekey
Root: HKCR; Subkey: "MyMAGIApplication\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\MAGI.EXE,0"
Root: HKCR; Subkey: "MyMAGIApplication\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\MAGI.EXE"" ""%1"""
我们在主Xaml中使用Startup
属性,以便像有用的主方法一样调用您的解析器。
<Application x:Class="MAGI.View.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="AppStartupMainMagi" >
</Application>
/// <summary>
/// Call with Startup property in App.xaml
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AppStartupMainMAGI(object sender, StartupEventArgs e)
{
String[] arguments = Environment.GetCommandLineArgs();
if (arguments.GetLength(0) > 1)
{
if (arguments[1].EndsWith(".magi"))
{
string filePathFormMainArgs = arguments[1];
if(isFileMagiValid(filePathFormMainArgs))
{
// Step 1 : deserialize filePathFormMainArgs
// Step 2 : call the view "File oepn" in the application"
}
}
}
else {
// Call the view "welcome page application"
}
}
你可以通过安装程序项目或ClickOnce安装来添加文件扩展名。一旦设置完成,用户可以双击一个.asog文件,你的应用程序将被调用,并且文件名将作为main函数参数数组中的第一个条目。