<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Label="Globals">
    <ProjectGuid>{5B0E9978-E76F-4BBC-8194-228323F59B53}</ProjectGuid>
    <RootNamespace>PortableInstaller</RootNamespace>
  </PropertyGroup>

  <ImportGroup Label="PropertySheets">
    <Import Project="$(MSBuildThisFileDirectory)..\aegisub.props" />
    <Import Project="$(MSBuildThisFileDirectory)..\git_version.xml" />
  </ImportGroup>

  <PropertyGroup>
    <PlatformName Condition="$(Platform) == 'Win32'">x86</PlatformName>
    <PlatformName Condition="$(Platform) == 'x64'">x64</PlatformName>
    <FileName>aegisub-$(GitVersionString)-portable-$(AegisubPlatformSuffix)</FileName>
    <OutputFile>$(AegisubSourceBase)packages\win_installer\output\$(FileName).exe</OutputFile>
  </PropertyGroup>

  <Target Name="Build">
    <Error
      Condition="!Exists($(WinRarPath))"
      Text="WinRAR.exe not found. Please set the path to it."
      />

    <MakeDir Directories="$(AegisubObjectDir)\$(FileName)" />
    <MakeDir Directories="$(AegisubSourceBase)\packages\win_installer\output" />

    <Copy
      SourceFiles="@(RarContents)"
      DestinationFiles="$(AegisubObjectDir)$(FileName)\%(RarContents.OutputPath)%(Filename)%(Extension)"
      SkipUnchangedFiles="true"
      />

    <Copy
      SourceFiles="@(RarMetafiles)"
      DestinationFolder="$(AegisubObjectDir)"
      SkipUnchangedFiles="true"
      />

    <Delete Files="$(OutputFile)" />

    <Exec
      Command="&quot;$(WinRarPath)&quot; a -sfx -s -m5 -ep1 -r -zportable-comment.txt -iimgside-logo.bmp -iiconicon.ico $(OutputFile) $(FileName)"
      WorkingDirectory="$(AegisubObjectDir)"
      />
  </Target>

  <ItemGroup>
    <RarContents Include="$(AegisubSourceBase)automation\autoload\cleantags-autoload.lua">
      <OutputPath>automation\autoload\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\autoload\kara-templater.lua">
      <OutputPath>automation\autoload\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\autoload\karaoke-auto-leadin.lua">
      <OutputPath>automation\autoload\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\autoload\macro-1-edgeblur.lua">
      <OutputPath>automation\autoload\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\autoload\macro-2-mkfullwitdh.lua">
      <OutputPath>automation\autoload\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\autoload\select-overlaps.moon">
      <OutputPath>automation\autoload\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\autoload\strip-tags.lua">
      <OutputPath>automation\autoload\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\demos\future-windy-blur.lua">
      <OutputPath>automation\demos\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\demos\raytracer.lua">
      <OutputPath>automation\demos\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\aegisub\argcheck.moon">
      <OutputPath>automation\include\aegisub\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\aegisub\clipboard.lua">
      <OutputPath>automation\include\aegisub\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\aegisub\ffi.moon">
      <OutputPath>automation\include\aegisub\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\aegisub\lfs.moon">
      <OutputPath>automation\include\aegisub\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\aegisub\re.moon">
      <OutputPath>automation\include\aegisub\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\aegisub\unicode.moon">
      <OutputPath>automation\include\aegisub\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\aegisub\util.moon">
      <OutputPath>automation\include\aegisub\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\cleantags.lua">
      <OutputPath>automation\include\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\clipboard.lua">
      <OutputPath>automation\include\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\karaskel-auto4.lua">
      <OutputPath>automation\include\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\karaskel.lua">
      <OutputPath>automation\include\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\moonscript.lua">
      <OutputPath>automation\include\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\re.lua">
      <OutputPath>automation\include\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\unicode.lua">
      <OutputPath>automation\include\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\utils-auto4.lua">
      <OutputPath>automation\include\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)automation\include\utils.lua">
      <OutputPath>automation\include\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)bin\AssDraw3.chm" />
    <RarContents Include="$(AegisubSourceBase)bin\AssDraw3.exe" />
    <RarContents Include="$(AegisubSourceBase)bin\DirectShowSource.dll" Condition="'$(AegisubUseAvisynth)' == 'true'" />
    <RarContents Include="$(AegisubSourceBase)bin\aegisub$(AegisubPlatformSuffix).exe" />
    <RarContents Include="$(AegisubSourceBase)bin\avisynth.dll" Condition="'$(AegisubUseAvisynth)' == 'true'" />
    <RarContents Include="$(AegisubSourceBase)bin\csri\xy-vsfilter-aegisub$(PlatformArchitecture).dll" Condition="'$(AegisubUseCsri)' == 'HelperLibrary'">
      <OutputPath>csri\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)bin\devil.dll" Condition="'$(AegisubUseAvisynth)' == 'true'" />
    <RarContents Include="$(AegisubSourceBase)packages\win_installer\portable\config.json" />
    <RarContents Include="$(AegisubSourceBase)bin\dictionaries\en_US.aff">
      <OutputPath>dictionaries\</OutputPath>
    </RarContents>
    <RarContents Include="$(AegisubSourceBase)bin\dictionaries\en_US.dic">
      <OutputPath>dictionaries\</OutputPath>
    </RarContents>
  </ItemGroup>
  <ItemGroup>
    <RarMetafiles Include="$(AegisubSourceBase)packages\win_installer\portable\icon.ico" />
    <RarMetafiles Include="$(AegisubSourceBase)packages\win_installer\portable\side-logo.bmp" />
    <RarMetafiles Include="$(AegisubSourceBase)packages\win_installer\portable\portable-comment.txt" />
  </ItemGroup>
</Project>
