~ubuntu-branches/ubuntu/precise/pingus/precise

« back to all changes in this revision

Viewing changes to src/path_manager.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Goulais
  • Date: 2004-08-09 10:26:00 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040809102600-lg2q9lfars0q1p42
Tags: 0.6.0-8
Applied patch from Andreas Jochens (Closes: #263992)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  $Id: path_manager.cxx,v 1.5 2003/04/13 23:33:19 grumbel Exp $
 
2
//
 
3
//  Pingus - A free Lemmings clone
 
4
//  Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
 
5
//
 
6
//  This program is free software; you can redistribute it and/or
 
7
//  modify it under the terms of the GNU General Public License
 
8
//  as published by the Free Software Foundation; either version 2
 
9
//  of the License, or (at your option) any later version.
 
10
//
 
11
//  This program is distributed in the hope that it will be useful,
 
12
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
//  GNU General Public License for more details.
 
15
//
 
16
//  You should have received a copy of the GNU General Public License
 
17
//  along with this program; if not, write to the Free Software
 
18
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
#include "globals.hxx"
 
21
#include "system.hxx"
 
22
#include "path_manager.hxx"
 
23
#include "debug.hxx"
 
24
 
 
25
PathManager path_manager;
 
26
 
 
27
PathManager::PathManager ()
 
28
  : path_found (false)
 
29
{
 
30
}
 
31
 
 
32
PathManager::~PathManager ()
 
33
{
 
34
}
 
35
 
 
36
void 
 
37
PathManager::add_path (const std::string& path)
 
38
{
 
39
  pout(PINGUS_DEBUG_PATHMGR) << "PathManager: add_path: " << path << std::endl;
 
40
  path_list.push_back (path);
 
41
}
 
42
 
 
43
std::string 
 
44
PathManager::complete (const std::string& relative_path)
 
45
{
 
46
  std::string comp_path = base_path + "/" + relative_path;
 
47
  pout(PINGUS_DEBUG_PATHMGR) << "PathManager: " << relative_path << " -> " << comp_path << std::endl;
 
48
  
 
49
  return comp_path;
 
50
}
 
51
 
 
52
bool 
 
53
PathManager::find_path (const std::list<std::string>& file_list)
 
54
{
 
55
  for (PathIter i = path_list.begin (); !path_found && i != path_list.end (); ++i)
 
56
    {
 
57
      bool found_file = true;
 
58
      for (PathIter f = file_list.begin (); found_file && f != file_list.end (); ++f)
 
59
        {
 
60
          if (!System::exist(*i + "/" + *f))
 
61
            found_file = false;
 
62
        }
 
63
      if (found_file)
 
64
        {
 
65
          path_found = true;
 
66
          base_path = *i;
 
67
 
 
68
          pout(PINGUS_DEBUG_PATHMGR) << "PathManager: Using base_path: " << base_path << std::endl;
 
69
 
 
70
          return true;
 
71
        }
 
72
    }
 
73
 
 
74
  pout(PINGUS_DEBUG_PATHMGR) << "PathManager: No base path found" << std::endl;
 
75
 
 
76
  return false;
 
77
}
 
78
 
 
79
/** Search for a path which contains the file 'file' */
 
80
bool 
 
81
PathManager::find_path (const std::string& file)
 
82
{
 
83
  for (PathIter i = path_list.begin (); !path_found && i != path_list.end (); ++i)
 
84
    {
 
85
      if (System::exist(*i + "/" + file))
 
86
        {
 
87
          path_found = true;
 
88
          base_path = *i;
 
89
 
 
90
          pout(PINGUS_DEBUG_PATHMGR) << "PathManager: Using base_path: " << base_path << std::endl;
 
91
 
 
92
          return true;
 
93
        }
 
94
    }
 
95
 
 
96
  pout(PINGUS_DEBUG_PATHMGR) << "PathManager: No base path found" << std::endl;
 
97
 
 
98
  return false;
 
99
}
 
100
 
 
101
void 
 
102
PathManager::set_path (const std::string& path)
 
103
{
 
104
  base_path = path;
 
105
}
 
106
 
 
107
/* EOF */