<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(DevEnvDir)\Extensions\Tools\MSBuild\AddonStudio\Common\3.0\CommonAddonStudio.targets" />
  <PropertyGroup>
    <AddonPath>$(DeployBasePath)\Interface\AddOns\$(Name)</AddonPath>
    <StartAction>Program</StartAction>
    <StartProgram>$(RuntimePath)\WoW.exe</StartProgram>
  </PropertyGroup>

  <Target Name="BeforeClean" />
  <Target Name="AfterClean" />
  <Target Name="BeforeRebuild" />
  <Target Name="AfterRebuild" />
  <Target Name="BeforeDeploy" />
  <Target Name="AfterDeploy" />
  <Target Name="AllProjectOutputGroups" />
  <Target Name="GetFrameworkPaths" />

  <Target Name="_CheckProperties">
    <Error Text="RuntimePath must be defined. Use the Tools > Options > AddOn Studio > World of Warcraft options page to set it to the location where WoW is installed."
      Condition="('$(RuntimePath)' == '') Or ('$(RuntimePath)' == '$wowpath$')" />
    <Error Text="DeployBasePath must be defined. Use the Tools > Options > AddOn Studio > World of Warcraft options page to set it to the base location where WoW AddOns are located."
      Condition="('$(DeployBasePath)' == '') Or ('$(DeployBasePath)' == '$wowpath$')" />
  </Target>

  <Target Name="Clean" DependsOnTargets="_CheckProperties">
    <CallTarget Targets="BeforeClean" />
    <CreateItem Include="@(Content)" AdditionalMetadata="TargetPath=$(AddonPath)\%(Content.Identity)">
      <Output TaskParameter="Include" ItemName="_FilesToDelete"/>
    </CreateItem>
    <Delete Files="%(_FilesToDelete.TargetPath)" />
    <CallTarget Targets="AfterClean" />
  </Target>

  <Target Name="Rebuild" DependsOnTargets="_CheckProperties">
    <CallTarget Targets="BeforeRebuild" />
    <CallTarget Targets="Clean" />
    <CallTarget Targets="Deploy" />
    <CallTarget Targets="AfterRebuild" />
  </Target>

  <Target Name="Deploy" DependsOnTargets="_CheckProperties">
    <Message Importance="High" Text="Deploying addon..." />
    <CallTarget Targets="BeforeDeploy" />
    <CreateItem Include="@(Content)" AdditionalMetadata="TargetPath=$(AddonPath)\%(Content.Identity);TargetDir=$(AddonPath)\%(Content.RelativeDir)">
      <Output TaskParameter="Include" ItemName="_AddonFiles"/>
    </CreateItem>
    <Message Importance="High" Text="Creating target folder structure..." />
    <MakeDir Directories="$(AddonPath)" />
    <MakeDir Directories="%(_AddonFiles.TargetDir)"/>
    <Message Importance="High" Text="Copying files..." />
    <Copy SourceFiles="@(_AddonFiles)" SkipUnchangedFiles="true" DestinationFiles="%(_AddonFiles.TargetPath)"/>
    <Message Importance="High" Text="Addon deployed." />
    <CallTarget Targets="AfterDeploy" />
  </Target>
</Project>