├── .gitattributes ├── src ├── main.cpp ├── filesystem.cpp ├── binaryio.h └── filesystem.h ├── .gitignore ├── vc12 ├── detfc.sln ├── detfc.vcxproj.filters └── detfc.vcxproj ├── license.txt └── readme.org /.gitattributes: -------------------------------------------------------------------------------- 1 | readme.org encoding=utf-8 2 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/misohena/detfc/master/src/main.cpp -------------------------------------------------------------------------------- /src/filesystem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/misohena/detfc/master/src/filesystem.cpp -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.ncb 3 | *.suo 4 | *.vcproj.*.user 5 | *.sdf 6 | *.opensdf 7 | *.vcxproj.user 8 | vc12/Debug/ 9 | vc12/Release/ 10 | -------------------------------------------------------------------------------- /vc12/detfc.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "detfc", "detfc.vcxproj", "{E4D68FED-9009-461A-9232-0C3ECA6734C2}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {E4D68FED-9009-461A-9232-0C3ECA6734C2}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {E4D68FED-9009-461A-9232-0C3ECA6734C2}.Debug|Win32.Build.0 = Debug|Win32 14 | {E4D68FED-9009-461A-9232-0C3ECA6734C2}.Release|Win32.ActiveCfg = Release|Win32 15 | {E4D68FED-9009-461A-9232-0C3ECA6734C2}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2014 AKIYAMA Kouhei 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | SOFTWARE. 18 | -------------------------------------------------------------------------------- /src/binaryio.h: -------------------------------------------------------------------------------- 1 | #ifndef DETFC_BINARYIO_H_INCLUDED 2 | #define DETFC_BINARYIO_H_INCLUDED 3 | 4 | #include 5 | #include 6 | 7 | namespace detfc{ 8 | 9 | // Binary I/O 10 | 11 | template 12 | void writeBinary(std::ostream &os, const T &v) 13 | { 14 | os.write(reinterpret_cast(&v), sizeof(v)); 15 | } 16 | 17 | template 18 | T readBinary(std::istream &is) 19 | { 20 | T v = T(); 21 | is.read(reinterpret_cast(&v), sizeof(v)); 22 | return v; 23 | } 24 | 25 | void writeStringBinary(std::ostream &os, std::string &v) 26 | { 27 | writeBinary(os, v.size()); 28 | os.write(v.data(), v.size()); 29 | } 30 | 31 | std::string readStringBinary(std::istream &is) 32 | { 33 | typedef char CHAR; 34 | const std::size_t size = readBinary(is); 35 | if (!is){ 36 | return std::string(); 37 | } 38 | if (size == 0){ 39 | return std::string(); 40 | } 41 | const std::size_t MAX_CHARS = 1024; 42 | if (size <= MAX_CHARS){ 43 | CHAR buf[MAX_CHARS]; 44 | is.read(buf, size); 45 | return std::string(buf, buf + size); 46 | } 47 | else{ 48 | std::unique_ptr buf(new CHAR[size]); 49 | is.read(buf.get(), size); 50 | return std::string(buf.get(), buf.get() + size); 51 | } 52 | } 53 | 54 | }//namespace detfc 55 | #endif 56 | -------------------------------------------------------------------------------- /vc12/detfc.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | ソース ファイル 23 | 24 | 25 | 26 | 27 | ヘッダー ファイル 28 | 29 | 30 | ヘッダー ファイル 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/filesystem.h: -------------------------------------------------------------------------------- 1 | #ifndef DETFC_FILESYSTEM_H_INCLUDED 2 | #define DETFC_FILESYSTEM_H_INCLUDED 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace detfc{ 9 | 10 | typedef char PathChar; 11 | typedef std::string PathString; 12 | #define PATH_CHAR_L(x) x 13 | 14 | // File Name 15 | 16 | PathString getPathFileNamePart(const PathString &s); 17 | PathString getPathNotFileNamePart(const PathString &s); 18 | bool isPathTerminatedByRedundantSeparator(const PathString &s); 19 | PathString getPathWithoutLastRedundantSeparator(const PathString &s); 20 | PathString getPathDirectoryPart(const PathString &s); 21 | PathString concatPath(const PathString &a, const PathString &b); 22 | 23 | // Directory Entry 24 | 25 | enum FileType 26 | { 27 | FILETYPE_ERROR, 28 | FILETYPE_REGULAR, 29 | FILETYPE_DIRECTORY 30 | }; 31 | typedef std::uint64_t FileTime; 32 | typedef std::uint64_t FileSize; 33 | 34 | class DirectoryEntry 35 | { 36 | PathString dir_; 37 | PathString filename_; 38 | FileType type_; 39 | FileSize size_; 40 | FileTime lastWriteTime_; 41 | public: 42 | DirectoryEntry( 43 | const PathString &dir = PathString(), 44 | const PathString &filename = PathString(), 45 | FileType type = FILETYPE_ERROR, 46 | FileSize size = 0, 47 | FileTime lastWriteTime = 0) 48 | : dir_(dir), filename_(filename), type_(type), size_(size), lastWriteTime_(lastWriteTime){} 49 | PathString getPath() const { return concatPath(dir_, filename_);} 50 | PathString getFilename() const { return filename_;} 51 | FileTime getLastWriteTime() const { return lastWriteTime_;} 52 | FileSize getFileSize() const { return size_;} 53 | FileType getFileType() const { return type_;} 54 | bool isDirectory() const { return type_ == FILETYPE_DIRECTORY;} 55 | bool isRegularFile() const { return type_ == FILETYPE_REGULAR;} 56 | 57 | void assign(const PathString &filename, FileType type, FileSize size, FileTime lastWriteTime) 58 | { 59 | filename_ = filename; 60 | type_ = type; 61 | size_ = size; 62 | lastWriteTime_ = lastWriteTime; 63 | } 64 | }; 65 | 66 | class DirectoryEntryEnumerator 67 | { 68 | class Impl; 69 | std::shared_ptr impl_; 70 | public: 71 | DirectoryEntryEnumerator(const PathString &dir); 72 | ~DirectoryEntryEnumerator(); 73 | const DirectoryEntry &getEntry() const; 74 | void increment(); 75 | bool isEnd() const; 76 | }; 77 | 78 | 79 | // File Operation 80 | 81 | FileType getPathFileType(const PathString &p); 82 | bool isPathExists(const PathString &p); 83 | bool isPathDirectory(const PathString &p); 84 | bool isPathRegularFile(const PathString &p); 85 | DirectoryEntry getPathDirectoryEntry(const PathString &p); 86 | FileTime getPathLastWriteTime(const PathString &p); 87 | FileTime getPathFileSize(const PathString &p); 88 | 89 | 90 | }//namespace detfc 91 | #endif 92 | -------------------------------------------------------------------------------- /readme.org: -------------------------------------------------------------------------------- 1 | Detect File Change 2 | 3 | * 概要 4 | detfcはファイルやディレクトリの変化を検出するコマンドラインツールです。 5 | 変化を検出したら、記録ファイルを更新したり、任意のコマンドを実行したりします。 6 | 7 | * コマンドライン 8 | 9 | #+BEGIN_QUOTE 10 | detfc [