Skip to content

Commit

Permalink
added support to launch edico from an .edi file. Added file association.
Browse files Browse the repository at this point in the history
  • Loading branch information
a.zanella committed Sep 7, 2023
1 parent 17a8b68 commit 15a389c
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 9 deletions.
55 changes: 54 additions & 1 deletion EdicoTI/EdicoFileChanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static bool deleteUserConfig(string xmlFile)
return true;
}

public static void crawlAndChange()
public static void crawlAndChange(string openFile)
{
string dataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
dataDir = Path.Combine(dataDir, "Apps", "2.0", "Data");
Expand All @@ -53,6 +53,10 @@ public static void crawlAndChange()
foreach(var file in configFiles)
{
changeUserConfig(file);
if(openFile != null)
{
setFileToOpen(file, openFile);
}
}
foreach (var file in keyboardFiles)
{
Expand Down Expand Up @@ -82,6 +86,55 @@ private static void changeUserConfig(string xmlFile)
doc.Save(xmlFile);
}

private static void setFileToOpen(string config, string openFilePath)
{
XDocument doc = XDocument.Load(config);
XElement elem = doc.Element("configuration");
if (elem == null) return;
elem = elem.Element("userSettings");
if (elem == null) return;
elem = elem.Element("Edico.Properties.Settings");
if (elem == null) return;
string filesOpenXMLPath = elem.Elements().Where(e =>
(e.Attribute("name").Value == "xmlData_path")).First().Value;
if (filesOpenXMLPath == null) return;
filesOpenXMLPath = Path.Combine(filesOpenXMLPath, "Model", "XMLs", "filesOpen.xml");
if (!File.Exists(filesOpenXMLPath)) return;
doc = XDocument.Load(filesOpenXMLPath);
elem = doc.Element("Files");
bool isPresent = false;
int maxPos = 0;
foreach(var xFile in elem.Elements())
{
string xPosition = xFile.Attribute("Position").Value;
if (xPosition != null)
{
int iPosition = Convert.ToInt16(xPosition);
if (iPosition >= maxPos) maxPos = iPosition + 1;
}
string xCurrent = xFile.Attribute("Current").Value;
if ((xCurrent != null) && (xCurrent == "1"))
{
xFile.Attribute("Current").Value = "0";
}
string xPath = xFile.Attribute("Path").Value;
if ((xPath != null) && (xPath.ToLower() == openFilePath.ToLower()))
{
xFile.Attribute("Current").Value = "1";
isPresent = true;
}
}
if (!isPresent)
{
XElement newFile = new XElement("File");
newFile.SetAttributeValue("Path", openFilePath);
newFile.SetAttributeValue("Position", maxPos);
newFile.SetAttributeValue("Current", "1");
elem.Add(newFile);
}
doc.Save(filesOpenXMLPath);
}

private static void changeShortcutXML(string xmlFile)
{
XDocument doc = XDocument.Load(xmlFile);
Expand Down
3 changes: 3 additions & 0 deletions EdicoTI/EdicoTI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
<Content Include="EdicoTray.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="fileIcon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
9 changes: 5 additions & 4 deletions EdicoTI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ public partial class MainForm : Form
{
private static string EDICO_CIDAT_DEPLOYMENT_URL = "http://cidat.once.es/repos/edico/Edico.application";
private int tick;
private string fileParam;
private ClickOnceApplicationService clickOnceService;
private JAWSManager jawsManager;
public MainForm()
public MainForm(string fileParam)
{
InitializeComponent();
this.clickOnceService = new ClickOnceApplicationService(EDICO_CIDAT_DEPLOYMENT_URL);
this.jawsManager = new JAWSManager();

}
this.fileParam = fileParam;
}

private void MainForm_Load(object sender, EventArgs e)
{
Expand Down Expand Up @@ -160,7 +161,7 @@ private void launchAll()
proc.StartInfo.FileName = Process.GetCurrentProcess().MainModule.FileName.ToLower().Replace("edicoti.exe", "EdicoTray.exe");
proc.StartInfo.UseShellExecute = true;
proc.Start();
EdicoFileChanger.crawlAndChange();
EdicoFileChanger.crawlAndChange(fileParam);
if (clickOnceService.isInstalled())
{
clickOnceService.runClickOnce();
Expand Down
7 changes: 6 additions & 1 deletion EdicoTI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ internal static class Program
[STAThread]
static void Main(string[] args)
{
string openFile = null;
if(args.Length > 0 && args[0].ToLower().Trim().EndsWith(".edi"))
{
openFile = args[0];
}
if (args.Length > 0 && args[0] == "/utility")
{
Application.EnableVisualStyles();
Expand All @@ -32,7 +37,7 @@ static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
Application.Run(new MainForm(openFile));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions EdicoTI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2023.1.0.0")]
[assembly: AssemblyFileVersion("2023.1.0.0")]
[assembly: AssemblyVersion("2023.2.0.0")]
[assembly: AssemblyFileVersion("2023.2.0.0")]
Binary file added EdicoTI/fileIcon.ico
Binary file not shown.
8 changes: 7 additions & 1 deletion edico.iss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SolidCompression=yes
AlwaysShowComponentsList=no
DisableWelcomePage=no
DisableProgramGroupPage=yes
ChangesAssociations = yes
UninstallDisplayIcon={app}\edicoTI.exe

[Languages]
Expand All @@ -54,9 +55,14 @@ Name: "{group}\Edico Targato Italia"; Filename: "{app}\EdicoTI.exe"; IconFilenam
Name: "{group}\Utility di Edico"; Filename: "{app}\EdicoTI.exe"; Parameters: "/utility"; IconFilename:{app}\EdicoTI.exe;
Name: {userdesktop}\Edico Targato Italia; Filename: {app}\EdicoTI.exe; IconFilename:{app}\EdicoTI.exe;

[Registry]
Root: HKCU; Subkey: "SOFTWARE\Classes\.edi"; ValueData: "Edico"; Flags: uninsdeletevalue; ValueType: string; ValueName: ""
Root: HKCU; Subkey: "SOFTWARE\Classes\Edico"; ValueData: "EdicoTI"; Flags: uninsdeletekey; ValueType: string; ValueName: ""
Root: HKCU; Subkey: "SOFTWARE\Classes\Edico\DefaultIcon";ValueData: "{app}\fileIcon.ico,0"; ValueType: string; ValueName: ""
Root: HKCU; Subkey: "SOFTWARE\Classes\Edico\shell\open\command"; ValueData: """{app}\edicoTI.exe"" ""%1"""; ValueType: string; ValueName: ""

[Code]

[Code]
function OldEdicoIsPresent: Boolean;
begin
Result := RegKeyExists(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\EDICO_is1');
Expand Down

0 comments on commit 15a389c

Please sign in to comment.