<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.5">

  <!-- Set some paths -->
  <PropertyGroup>
    <SourceDir>src</SourceDir>
    <PublishDir>publish</PublishDir>
    <InstallPrefix>/usr/local</InstallPrefix>
    <InstallBinDir>$(InstallPrefix)/bin</InstallBinDir>
    <InstallLibDir>$(InstallPrefix)/lib</InstallLibDir>
    <InstallDataRootDir>$(InstallPrefix)/share</InstallDataRootDir>
    <InstallManDir>$(InstallDataRootDir)/man</InstallManDir>
    <InstallLocaleDir>$(InstallDataRootDir)/locale</InstallLocaleDir>
  </PropertyGroup>

  <!-- All of our compiled translation files -->
  <ItemGroup>
      <Translation Include="$(PublishDir)/locale/**/pinta.mo"/>
  </ItemGroup>

  <!-- All of our icons -->
  <ItemGroup>
      <Icon Include="$(PublishDir)/icons/**/*.png"/>
      <Icon Include="$(PublishDir)/icons/**/*.svg"/>
  </ItemGroup>

  <!-- Reference all of our assemblies -->
  <ItemGroup>
    <BinFile Include="$(PublishDir)/*.dll" />
    <BinFile Include="$(PublishDir)/*.json" />
  </ItemGroup>

  <!-- Install everything for Pinta -->
  <Target Name="Install">
    <Copy SourceFiles="@(BinFile)" DestinationFolder="$(InstallLibDir)/pinta" />
    <MakeDir Directories="$(InstallBinDir)" />
    <Copy SourceFiles="$(SourceDir)/xdg/pinta.1" DestinationFolder="$(InstallManDir)/man1" />
    <Exec Command='gzip -f "$(InstallManDir)/man1/pinta.1"' />
    <Copy SourceFiles="$(SourceDir)/xdg/com.github.PintaProject.Pinta.metainfo.xml" DestinationFolder="$(InstallDataRootDir)/metainfo" />
    <Copy SourceFiles="$(SourceDir)/xdg/com.github.PintaProject.Pinta.desktop" DestinationFolder="$(InstallDataRootDir)/applications" />
    <Copy SourceFiles="@(Icon)" DestinationFolder="$(InstallDataRootDir)/icons/%(Icon.RecursiveDir)" />
    <Copy SourceFiles="@(Translation)" DestinationFolder="$(InstallLocaleDir)/%(Translation.RecursiveDir)" />
  </Target>

  <!-- Uninstall everything for Pinta -->
  <Target Name="Uninstall">
    <Exec Command='rm -rf "$(InstallLibDir)/pinta"' />
    <Delete Files="$(InstallBinDir)/pinta" />
    <Delete Files="$(InstallLocaleDir)/%(Translation.Code)/LC_MESSAGES/pinta.mo" />
    <Delete Files="$(InstallManDir)/man1/pinta.1" />
    <Delete Files="$(InstallManDir)/man1/pinta.1.gz" />
    <Delete Files="$(InstallDataRootDir)/metainfo/com.github.PintaProject.Pinta.metainfo.xml" />
    <Delete Files="$(InstallDataRootDir)/applications/com.github.PintaProject.Pinta.desktop" />
    <Delete Files="$(InstallDataRootDir)/icons/%(Icon.RecursiveDir)/%(Icon.Filename)%(Icon.Extension)" />
    <Delete Files="$(InstallLocaleDir)/%(Translation.RecursiveDir)/pinta.mo" />
  </Target>
</Project>
