Skip to content

Commit

Permalink
Add regex for ignoring certain files
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaugh committed Oct 28, 2011
1 parent df92e41 commit 7de5930
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC=g++
CFLAGS=-I.
LIBS=-lboost_system -lboost_thread -lboost_filesystem
LIBS=-lboost_system -lboost_thread -lboost_filesystem -lboost_regex

patcher:
$(CC) file_manager.cpp patch_list.cpp downloader.cpp patch_manager.cpp main.cpp $(LIBS) -o patcher
Expand Down
23 changes: 16 additions & 7 deletions patch_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

void PatchManager::get_patch()
{
ignore_regex = boost::regex("[\\d\\w]+\\.(cpp|h|obj)|makefile", boost::regex_constants::icase);

downloader.init("www.leaiva.com", "80", "/patch");
download_patch_file();
download_patch_contents();

std::cout << std::endl;
std::cout << "Patch list received" << std::endl;
downloader.run();
//downloader.run();
}

void PatchManager::download_patch_file()
Expand All @@ -23,7 +25,7 @@ void PatchManager::download_patch_file()
void PatchManager::download_patch_contents()
{
std::string line = "";
std::ifstream patch("data/patch.txt");
std::ifstream patch("patch/patch.txt");
int index;
int line_num = 0;
std::string checksum;
Expand All @@ -42,11 +44,18 @@ void PatchManager::download_patch_contents()
filename = line.substr(0, index);
checksum = line.substr(index + 1);

// If the local file's checksum doesn't match the
// checksum on the patch file, we know that the file is
// out of date, so download it.
if(checksum != FileManager::checksum(filename)) {
downloader.get(filename, checksum);
// Do not try to download if the file is meant to be ignored
if(!boost::regex_match(filename, ignore_regex)) {

// If the local file's checksum doesn't match the
// checksum on the patch file, we know that the file is
// out of date, so download it.
if(checksum != FileManager::checksum(filename)) {
downloader.get(filename, checksum);
}
}
else {
std::cout << filename << " ignored" << std::endl;
}
}
else {
Expand Down
2 changes: 2 additions & 0 deletions patch_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "downloader.h"
#include "file_manager.h"
#include <boost/regex.hpp>


class PatchManager
Expand All @@ -16,4 +17,5 @@ class PatchManager

protected:
Downloader downloader;
boost::regex ignore_regex;
};

0 comments on commit 7de5930

Please sign in to comment.