Implement hybrid webapplication installation
[platform/core/appfw/wgt-backend.git] / src / wgt / rds_parser.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "wgt/rds_parser.h"
6
7 #include <fstream>
8
9 namespace {
10 const char kAdd[] = "#add";
11 const char kModify[] = "#modify";
12 const char kDelete[] = "#delete";
13 }
14
15 namespace wgt {
16 namespace rds_parser {
17
18 RDSParser::RDSParser(const std::string& path_to_delta)
19   : path_to_delta_(path_to_delta) {}
20
21 bool RDSParser::Parse() {
22   std::vector<std::string>* current_container = nullptr;
23   std::string line;
24
25   std::ifstream file_to_parse(path_to_delta_);
26   if (!file_to_parse.is_open())
27     return false;
28   while (getline(file_to_parse, line)) {
29     if (line.compare(kDelete) == 0) {
30       current_container = &files_to_delete_;
31       continue;
32     }
33     if (line.compare(kAdd) == 0) {
34       current_container = &files_to_add_;
35       continue;
36     }
37     if (line.compare(kModify) == 0) {
38       current_container = &files_to_modify_;
39       continue;
40     }
41     if (current_container)
42       current_container->push_back(line);
43   }
44   file_to_parse.close();
45   return true;
46 }
47
48 const std::vector<std::string>& RDSParser::files_to_modify() const {
49   return files_to_modify_;
50 }
51
52 const std::vector<std::string>& RDSParser::files_to_add() const {
53   return files_to_add_;
54 }
55
56 const std::vector<std::string>& RDSParser::files_to_delete() const {
57   return files_to_delete_;
58 }
59
60 }  // namespace rds_parser
61 }  // namespace wgt