// Protra - Easy trading system development environment.
// Copyright(C) 2003 Daisuke Arai <darai@users.sourceforge.jp>
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
// 
// $Id: LhaExtracter.cs 263 2010-01-16 13:12:35Z panacoran $

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Protra.Lib.Archiver
{
	/// <summary>
	/// LhaのIExtracterです。
	/// </summary>
	public class LhaExtracter : IExtracter
	{
		[DllImport("unlha32.dll")]
		private static extern int Unlha(
			int hwnd, string szCmdLine, string szOutput, int dwSize);

		/// <summary>
		/// 解凍します。
		/// </summary>
		/// <param name="file">圧縮ファイル</param>
		/// <param name="dir">解凍先ディレクトリ</param>
		public void Extract(string file, string dir)
		{
			if(dir[dir.Length - 1] != Path.DirectorySeparatorChar)
				dir += Path.DirectorySeparatorChar;
			string cmd = "e -n \"" + file + "\" \"" + dir + "\"";
			Unlha(0, cmd, null, 0);
		}
	}
}
