BOOL CFileBasedProjectTemplateItem::CreateMainFile(LPCTSTR lpszTargetPath, LPCTSTR lpszCrLf)
{
	CStringW text;
	TextDocument doc;

	bool result = doc.Read(m_strPath,text);

	if (result)
	{
		const CStringW lineendings(L"\r\n");
		int index = text.FindOneOf(lineendings);

		if (index != -1)
		{
			CStringW line = text.Left(index);
			const CStringW strKey(L"%DESCRIPTION: ");
			CStringW strStartOfLine = line.Left(strKey.GetLength());

			strStartOfLine.MakeUpper();

			if (strKey == strStartOfLine) 
			{
				text.Delete(0,index);
				text.TrimLeft(lineendings + L' ');
			}
		}

		LPCWSTR le = GetLineEnding(static_cast<LPCWSTR>(text),text.GetLength());

		USES_CONVERSION;

		if (std::wcscmp(le,T2CW(lpszCrLf)) != 0) // Line endings not equal
			text.Replace(le,lpszCrLf);

		result = doc.Write(lpszTargetPath,text);
	}

	return result;
}
LRESULT
RemoteRepositoryPage::OnFillList (/*[in]*/ WPARAM		wParam,
				  /*[in]*/ LPARAM		lParam)
{
  UNUSED_ALWAYS (wParam);
  UNUSED_ALWAYS (lParam);

  try
    {
      if (pSheet->GetCancelFlag() || pSheet->GetErrorFlag())
	{
	  SetProgressText (pSheet->GetCancelFlag()
			   ? T_("Cancelled")
			   : T_("Unsuccessful"));
	  pSheet->EnableCloseButton ();
	  return (0);
	}

      if (! listControl.DeleteAllItems())
	{
	  FATAL_WINDOWS_ERROR ("CListCtrl::DeleteAllItems", 0);
	}
      
      bool selected = false;

      int idx = 0;

      for (vector<RepositoryInfo>::const_iterator it = repositories.begin();
	   it != repositories.end();
	   ++ it, ++ idx)
	{
#if MIKTEX_RELEASE_STATE < 4
	  if (it->packageLevel < theApp.GetPackageLevel())
	    {
	      continue;
	    }
#endif

	  LV_ITEM lvitem;
	  
	  lvitem.iItem = idx;
	  lvitem.mask = LVIF_PARAM;
	  lvitem.lParam = idx;
	  lvitem.iSubItem = 0;
	  
	  if (listControl.InsertItem(&lvitem) < 0)
	    {
	      FATAL_WINDOWS_ERROR ("CListCtrl::InsertItem", 0);
	    }

	  string protocol;
	  string host;

	  SplitUrl (it->url, protocol, host);

	  SetItemText (idx, 0, it->country.c_str());
	  CStringW protUC = UW_(protocol.c_str());
	  protUC.MakeUpper ();
	  SetItemText (idx, 1, WU_(protUC));
	  SetItemText (idx, 2, host.c_str());
      	  SetItemText (idx, 3, TU_(CTime(it->timeDate).Format(_T("%d-%b-%y"))));
#if SHOW_DESCRIPTION
	  SetItemText (idx, 4, it->description.c_str());
#endif

	  if (it->url == theApp.GetRemotePackageRepository())
	    {
	      if (! listControl.SetItemState(idx,
					     LVIS_SELECTED,
					     LVIS_SELECTED))
		{
		  FATAL_WINDOWS_ERROR ("CListCtrl::SetItemState", 0);
		}
	      selected = true;
	    }
	}

      pSheet->SetWizardButtons (PSWIZB_BACK
				| (selected ? PSWIZB_NEXT : 0));
    }
  catch (const MiKTeXException & e)
    {
      pSheet->ReportError (e);
    }
  catch (const exception & e)
    {
      pSheet->ReportError (e);
    }
  
  return (0);
}