<?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/pinta.appdata.xml" DestinationFolder="$(InstallDataRootDir)/metainfo" />
    <Copy SourceFiles="$(SourceDir)/xdg/pinta.desktop" DestinationFolder="$(InstallDataRootDir)/applications" />
    <Copy SourceFiles="$(SourceDir)/xdg/pinta.xpm" DestinationFolder="$(InstallDataRootDir)/pixmaps" />
    <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/pinta.appdata.xml" />
    <Delete Files="$(InstallDataRootDir)/applications/pinta.desktop" />
    <Delete Files="$(InstallDataRootDir)/pixmaps/pinta.xpm" />
    <Delete Files="$(InstallDataRootDir)/icons/%(Icon.RecursiveDir)/%(Icon.Filename)%(Icon.Extension)" />
    <Delete Files="$(InstallLocaleDir)/%(Translation.RecursiveDir)/pinta.mo" />
  </Target>
</Project>
