├── images └── stacky.ico ├── binaries └── stacky-x64.zip ├── src ├── resource.h ├── stacky.rc └── stacky.cpp ├── vsproj ├── stacky.sln └── stacky.vcxproj ├── README.md └── LICENSE /images/stacky.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawelt/stacky/HEAD/images/stacky.ico -------------------------------------------------------------------------------- /binaries/stacky-x64.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawelt/stacky/HEAD/binaries/stacky-x64.zip -------------------------------------------------------------------------------- /src/resource.h: -------------------------------------------------------------------------------- 1 | #define STACKY_ICON_ID 101 2 | 3 | #define STACKY_VERSION 0,3,1 4 | #define STACKY_VERSION_STR L"0.3.1" 5 | 6 | #define STACKY_COPYRIGHT_STR L"2013 Tengi Design, Pawel Turlejski" 7 | -------------------------------------------------------------------------------- /src/stacky.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "resource.h" 3 | 4 | STACKY_ICON_ID ICON "..\\images\\stacky.ico" 5 | 6 | VS_VERSION_INFO VERSIONINFO 7 | FILEVERSION STACKY_VERSION 8 | PRODUCTVERSION STACKY_VERSION 9 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 10 | FILEOS VOS__WINDOWS32 11 | FILETYPE VFT_DLL 12 | FILESUBTYPE VFT2_UNKNOWN 13 | BEGIN 14 | BLOCK "StringFileInfo" 15 | BEGIN 16 | BLOCK "040904E4" 17 | BEGIN 18 | VALUE "CompanyName", "Tengi Design" 19 | VALUE "LegalCopyright", STACKY_COPYRIGHT_STR 20 | VALUE "OriginalFilename", "stacky.exe" 21 | VALUE "ProductName", "Stacky" 22 | VALUE "ProductVersion", STACKY_VERSION_STR 23 | END 24 | END 25 | BLOCK "VarFileInfo" 26 | BEGIN 27 | VALUE "Translation", 0x409, 1252 28 | END 29 | END 30 | -------------------------------------------------------------------------------- /vsproj/stacky.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 11 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stacky", "stacky.vcxproj", "{D682ECE4-5A51-458F-9A05-064C15562B6A}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D682ECE4-5A51-458F-9A05-064C15562B6A}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {D682ECE4-5A51-458F-9A05-064C15562B6A}.Debug|Win32.Build.0 = Debug|Win32 16 | {D682ECE4-5A51-458F-9A05-064C15562B6A}.Debug|x64.ActiveCfg = Debug|x64 17 | {D682ECE4-5A51-458F-9A05-064C15562B6A}.Debug|x64.Build.0 = Debug|x64 18 | {D682ECE4-5A51-458F-9A05-064C15562B6A}.Release|Win32.ActiveCfg = Release|Win32 19 | {D682ECE4-5A51-458F-9A05-064C15562B6A}.Release|Win32.Build.0 = Release|Win32 20 | {D682ECE4-5A51-458F-9A05-064C15562B6A}.Release|x64.ActiveCfg = Release|x64 21 | {D682ECE4-5A51-458F-9A05-064C15562B6A}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Stacky] Simple icon stacks solution for Windows 2 | ============================================================================================ 3 | 4 | WARNING: This project is no longer maintained. 5 | ---------------------------------------------- 6 | 7 | As you can tell from the commit history, the project hasn't been updated for a long time. Since I no longer use Windows, 8 | I don't really have an easy way to even compile it anymore. 9 | 10 | Thank you for your kind words in the open issues (I just closed them all, as I won't be able to address them). 11 | 12 | Please feel free to fork the project and improve it. Good luck! :) 13 | 14 | 15 | What is it 16 | ---------- 17 | 18 | Stacky is a small program for Windows that displays contents of a given directory as a list of clickable, labled icons. 19 | 20 | 21 | Installation 22 | ------------ 23 | 24 | There is no installation. Just download precompiled package from `binaries` directory (`stacky-x64.zip`, also contains CRT dependencies) and unzip. 25 | 26 | Direct link to precompiled binaries: https://github.com/pawelt/stacky/blob/master/binaries/stacky-x64.zip?raw=true 27 | 28 | 29 | Compilation 30 | ----------- 31 | 32 | You can build Stacky with free Microsoft tools, using solution file in the `vsproj` directory. 33 | 34 | Full source code (about 500 lines of C++ code) is available in `src` directory. 35 | 36 | 37 | How to use it 38 | ------------- 39 | 40 | 1. Create a regular windows shortcut to `stacky.exe`. 41 | 2. Create a folder and put shortcuts to your programs there. 42 | 3. Edit the shortcut and add the folder's path to the `Target` field, so it looks something like this: 43 | 44 | `D:\pawel\Programs\Stacky\stacky.exe D:\pawel\Stacks\Games` 45 | 46 | 4. Drag the stack shortcut to your taskbar. 47 | 48 | That's all. You can click the Stacky shortcut on the taskbar to open the new stack. 49 | 50 | 51 | Why is it useful 52 | ---------------- 53 | 54 | You can replace a bunch of icons on your taskbar with one icon. 55 | 56 | Say you use Photoshop, Illustrator, Axure and couple other design-related programs. Instead of putting individual shortucts in your taskbar, you can create a folder called "Design", put all your design shortcuts there and create one shortcut on a taskbar. 57 | 58 | Whenever you click on the icon, you will see all the icons you put in the folder, ready to launch. 59 | 60 | If you have 30+ programs, it is really convenient to split them into couple groups, instead of squizing in all icons right in the taskbar. 61 | 62 | Stacks with shortcuts to folders to your projects, movies, pictures and anything else work great too. 63 | 64 | 65 | Why would you use Stacky instead of... 66 | -------------------------------------- 67 | 68 | There are couple products on the market that do similar thing, like [RocketDock](http://rocketdock.com/) or [7stacks](http://alastria.com/software/7stacks/). In fact, I used 7stacks for quite some time. These are fine products, but stacky has some unique features that you may like: 69 | 70 | - it is open source and 100% free 71 | - it does one thing and does it well 72 | - it's very small, requires no installation, no external configuration etc. 73 | - but most of all, it's the fastest available solution 74 | 75 | 76 | Why is it so fast? 77 | ------------------ 78 | 79 | Because Stacky caches stacked icons. Instead of reading and analyzing `.lnk` files (Windows shortcuts), and then fetching icons from corresponding executables every time you open a stack, Stacky stores all icons in one small file in the stack folder. When user opens a stack, no `.lnk` file nor `.exe` files are touched. Only Stacky cache file. 80 | 81 | Any time the shortcuts folder is modified (new shrtcut is added etc.), the cache is rebuilt. 82 | 83 | 7stacks every now and then makes you wait good couple seconds, before it renders the stack. Stacky never, ever does it. Stacks are displayed immediately, every time. 84 | 85 | That's why stacky is faster than anything I've seen so far. 86 | 87 | 88 | -------------------------------------------------------------------------------- /vsproj/stacky.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {D682ECE4-5A51-458F-9A05-064C15562B6A} 23 | Win32Proj 24 | stacky 25 | $(VCTargetsPath11) 26 | 27 | 28 | 29 | Application 30 | true 31 | Unicode 32 | v120 33 | 34 | 35 | Application 36 | true 37 | Unicode 38 | v120 39 | 40 | 41 | Application 42 | false 43 | true 44 | Unicode 45 | v120 46 | 47 | 48 | Application 49 | false 50 | true 51 | Unicode 52 | v120 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | true 72 | $(SolutionDir)x86\$(Configuration)\ 73 | x86\$(Configuration)\ 74 | 75 | 76 | true 77 | C:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64;$(LibraryPath) 78 | 79 | 80 | false 81 | $(SolutionDir)x86\$(Configuration)\ 82 | x86\$(Configuration)\ 83 | 84 | 85 | false 86 | C:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64;$(LibraryPath) 87 | 88 | 89 | 90 | 91 | 92 | Level3 93 | Disabled 94 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 95 | 96 | 97 | Windows 98 | true 99 | 100 | 101 | 102 | 103 | 104 | 105 | Level3 106 | Disabled 107 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 108 | 109 | 110 | Windows 111 | true 112 | 113 | 114 | 115 | 116 | Level3 117 | 118 | 119 | MaxSpeed 120 | true 121 | true 122 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 123 | 124 | 125 | Windows 126 | true 127 | true 128 | true 129 | MachineX86 130 | 131 | 132 | 133 | 134 | Level3 135 | 136 | 137 | MaxSpeed 138 | true 139 | true 140 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 141 | 142 | 143 | Windows 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | 3 | Version 2.0, January 2004 4 | 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 16 | 17 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 18 | 19 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 20 | 21 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 22 | 23 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 24 | 25 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 26 | 27 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 28 | 29 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 30 | 31 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 32 | 33 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 34 | 35 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 36 | 37 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 38 | 39 | You must cause any modified files to carry prominent notices stating that You changed the files; and 40 | 41 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 42 | 43 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 44 | 45 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 46 | 47 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 48 | 49 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 50 | 51 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 52 | 53 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 54 | 55 | END OF TERMS AND CONDITIONS 56 | -------------------------------------------------------------------------------- /src/stacky.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | * System libs 3 | **************************************************************************************************/ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #pragma comment(lib, "Comctl32.lib") 9 | 10 | /************************************************************************************************** 11 | * Standard libs 12 | **************************************************************************************************/ 13 | #include 14 | #include 15 | #include 16 | 17 | #include "resource.h" // for version info 18 | 19 | /************************************************************************************************** 20 | * Simple types and constants 21 | **************************************************************************************************/ 22 | typedef wchar_t Char; 23 | typedef unsigned char Byte; 24 | typedef __time64_t Time; 25 | typedef std::wstring String; 26 | typedef std::vector StringList; 27 | 28 | const String CACHE_FILE_NAME = L"!stacky.cache"; 29 | const String STACKY_EXEC_NAME = L"stacky.exe"; 30 | const Char* STACKY_WINDOW_NAME = L"stacky"; 31 | const Char* DIR_SEP = L"\\"; 32 | 33 | enum { 34 | WM_BASE = WM_USER + 100, 35 | WM_OPEN_TARGET_FOLDER = WM_BASE + 1, 36 | WM_MENU_ITEM = WM_BASE + 2, 37 | 38 | APP_EXIT_DELAY = 3 * 1000, 39 | 40 | ERR_PATH_MISSING = 401, 41 | ERR_PATH_INVALID = 402, 42 | ERR_PARAM_UNKNOWN = 403, 43 | }; 44 | 45 | /************************************************************************************************** 46 | * The meat 47 | **************************************************************************************************/ 48 | 49 | struct Util { 50 | 51 | static String rtrim(const String& target, const String& trim) { 52 | size_t cutoff_pos = target.size() - trim.size(); 53 | return target.rfind(trim) == cutoff_pos ? target.substr(0, cutoff_pos) : target; 54 | } 55 | static String ltrim(const String& target, const String& trim) { 56 | size_t cutoff_pos = trim.size(); 57 | return target.find(trim) != String::npos ? target.substr(cutoff_pos) : target; 58 | } 59 | static String trim(const String& target, const String& trim) { 60 | return rtrim(ltrim(target, trim), trim); 61 | } 62 | static String quote(const String& target) { 63 | return L"\"" + target + L"\""; 64 | } 65 | static void kill_other_stackies() { 66 | PROCESSENTRY32 entry = { 0 }; 67 | entry.dwSize = sizeof(PROCESSENTRY32); 68 | BOOL found = false; 69 | HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); 70 | do { 71 | found = ::Process32Next(snapshot, &entry); 72 | if (entry.th32ProcessID != ::GetCurrentProcessId() && entry.szExeFile == STACKY_EXEC_NAME) { 73 | HANDLE hOtherStacky = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); 74 | if (hOtherStacky) { 75 | ::TerminateProcess(hOtherStacky, 0); 76 | ::CloseHandle(hOtherStacky); 77 | } 78 | else { 79 | Util::msg(L"Failed to open another stacky.exe process. Kill stacky.exe manually."); 80 | } 81 | } 82 | } while(found); 83 | ::CloseHandle(snapshot); 84 | } 85 | static Time get_modified(const String& file_path) { 86 | struct _stat buf; 87 | return _wstat(file_path.c_str(), &buf) ? 0 : buf.st_mtime; 88 | } 89 | static int parse_cmd_line(const String& cmd_line, String& stack_path, String& opts) { 90 | stack_path = cmd_line; 91 | if (stack_path.size() < 1) { 92 | return ERR_PATH_MISSING; 93 | } 94 | DWORD attrs = ::GetFileAttributes(trim(stack_path, L"\"").c_str()); 95 | if (attrs == INVALID_FILE_ATTRIBUTES || !(attrs & FILE_ATTRIBUTE_DIRECTORY)) { 96 | return ERR_PATH_INVALID; 97 | } 98 | return 0; 99 | } 100 | static void msgt(const String& title, const String& format, ...) { 101 | static Char msgBuf[4096] = { 0 }; 102 | va_list arglist; 103 | va_start(arglist, format); 104 | vswprintf(msgBuf, format.c_str(), arglist); 105 | va_end(arglist); 106 | ::MessageBox(0, msgBuf, title.c_str(), MB_OK | MB_ICONINFORMATION); 107 | } 108 | static void msg(const String& format, ...) { 109 | static Char msgBuf[4096] = { 0 }; 110 | va_list arglist; 111 | va_start(arglist, format); 112 | vswprintf(msgBuf, format.c_str(), arglist); 113 | va_end(arglist); 114 | ::MessageBox(0, msgBuf, L"Stacky", MB_OK | MB_ICONINFORMATION); 115 | } 116 | }; 117 | 118 | struct Buffer { 119 | size_t capacity, size; 120 | Byte* data; 121 | 122 | Buffer() : capacity(0), size(0), data(0) {} 123 | ~Buffer() { } 124 | 125 | void free() { 126 | if (data) { 127 | delete [] data; 128 | data = 0; 129 | } 130 | capacity = size = 0; 131 | } 132 | bool load(const String& str, bool append_null) { 133 | load(str.c_str(), str.size() * sizeof(Char)); 134 | if (append_null) { 135 | Char str_end[1] = { 0 }; 136 | load(str_end, sizeof(Char)); 137 | } 138 | return true; 139 | } 140 | bool load(const void* src, size_t src_size) { 141 | grow(src_size + size); 142 | memcpy(data + size, src, src_size); 143 | size += src_size; 144 | return true; 145 | } 146 | bool load(const String& file_path) { 147 | FileWrap f(file_path, L"rb"); 148 | if (!f.is_open()) { 149 | return false; 150 | } 151 | size_t file_size = f.size(); 152 | if (!file_size) { 153 | return false; 154 | } 155 | grow(file_size + size); 156 | f.read(data + size, file_size); 157 | size += file_size; 158 | return true; 159 | } 160 | bool save(const String& file_path) { 161 | FileWrap f(file_path, L"wb"); 162 | if (!f.is_open()) { 163 | return false; 164 | } 165 | f.write(data, size); 166 | return true; 167 | } 168 | 169 | private: 170 | struct FileWrap { 171 | FILE* f; 172 | FileWrap(const String& path, const String& mode) { f = _wfopen(path.c_str(), mode.c_str()); } 173 | ~FileWrap() { f && fclose(f); f = 0; } 174 | bool is_open() { return f != 0; } 175 | size_t write(Byte* data, size_t size) { return fwrite(data, 1, size, f); } 176 | size_t read(Byte* data, size_t size) { return fread(data, 1, size, f); } 177 | size_t size() { 178 | fseek(f, 0L, SEEK_END); 179 | size_t file_size = ftell(f); 180 | fseek(f, 0L, SEEK_SET); 181 | return file_size; 182 | } 183 | }; 184 | void grow(size_t new_capacity) { 185 | if (capacity >= new_capacity) { 186 | return; 187 | } 188 | size_t old_size = size; 189 | Byte* new_data = new Byte[new_capacity]; 190 | size && memcpy(new_data, data, capacity); 191 | free(); 192 | data = new_data; 193 | capacity = new_capacity; 194 | size = old_size; 195 | } 196 | }; 197 | 198 | struct Bmp { 199 | 200 | BITMAPFILEHEADER file_header; 201 | BITMAPINFOHEADER info_header; 202 | Buffer bits; 203 | HBITMAP hBmp; 204 | 205 | Bmp() : hBmp(0) { 206 | memset(&file_header, 0, sizeof(BITMAPFILEHEADER)); 207 | memset(&info_header, 0, sizeof(BITMAPINFOHEADER)); 208 | } 209 | 210 | void close() { 211 | ::DeleteObject(hBmp); 212 | bits.free(); 213 | hBmp = 0; 214 | memset(&file_header, 0, sizeof(BITMAPFILEHEADER)); 215 | memset(&info_header, 0, sizeof(BITMAPINFOHEADER)); 216 | } 217 | int total_size() { 218 | return file_header.bfSize; 219 | } 220 | int bits_size() { 221 | return file_header.bfSize - sizeof(BITMAPINFOHEADER) - sizeof(BITMAPFILEHEADER); 222 | } 223 | bool load_bits_and_headers(Byte* bytes) { 224 | close(); 225 | int pos = 0; 226 | memcpy(&file_header, bytes + pos, sizeof(BITMAPFILEHEADER)); 227 | pos += sizeof(BITMAPFILEHEADER); 228 | memcpy(&info_header, bytes + pos, sizeof(BITMAPINFOHEADER)); 229 | pos += sizeof(BITMAPINFOHEADER); 230 | return fill_bitmap(bytes + pos, bits_size()); 231 | } 232 | bool load_bits_only(Byte* bytes, int bits_size, int width, int height) { 233 | close(); 234 | memset(&file_header, 0, sizeof(BITMAPFILEHEADER)); 235 | file_header.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bits_size; 236 | file_header.bfType = 0x4d42; 237 | file_header.bfOffBits = 0x36; 238 | info_header = create_info_header(width, height); 239 | return fill_bitmap(bytes, bits_size); 240 | } 241 | bool serialize(Buffer& buffer) { 242 | buffer.load(&file_header, sizeof(BITMAPFILEHEADER)); 243 | buffer.load(&info_header, sizeof(BITMAPINFOHEADER)); 244 | buffer.load(bits.data, bits.size); 245 | return true; 246 | } 247 | static BITMAPINFOHEADER create_info_header(int width, int height) { 248 | BITMAPINFOHEADER bmih = { 0 }; 249 | bmih.biSize = sizeof(BITMAPINFOHEADER); 250 | bmih.biWidth = width; 251 | bmih.biHeight = height; 252 | bmih.biPlanes = 1; 253 | bmih.biBitCount = 32; 254 | bmih.biCompression = BI_RGB; 255 | return bmih; 256 | } 257 | static bool convert_file_icon(const HICON icon, Bmp& bmp) { 258 | static IWICImagingFactory* img_factory = 0; 259 | if (!img_factory) { 260 | // In VS 2011 beta, clsid has to be changed to CLSID_WICImagingFactory1 (from CLSID_WICImagingFactory) 261 | if (!SUCCEEDED(::CoInitialize(0)) || !SUCCEEDED(::CoCreateInstance(CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&img_factory)))) { 262 | return false; 263 | } 264 | } 265 | IWICBitmap* pBitmap = 0; 266 | IWICFormatConverter* pConverter = 0; 267 | UINT cx = 0, cy = 0; 268 | if (SUCCEEDED(img_factory->CreateBitmapFromHICON(icon, &pBitmap))) { 269 | if (SUCCEEDED(img_factory->CreateFormatConverter(&pConverter))) { 270 | if (SUCCEEDED(pConverter->Initialize(pBitmap, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, 0, 0.0f, WICBitmapPaletteTypeCustom))) { 271 | if (SUCCEEDED(pConverter->GetSize(&cx, &cy))) { 272 | const UINT stride = cx * sizeof(DWORD); 273 | const UINT buf_size = cy * stride; 274 | Byte* buf = new Byte[buf_size]; 275 | pConverter->CopyPixels(0, stride, buf_size, buf); 276 | bmp.load_bits_only(buf, buf_size, cx, -(int)cy); 277 | delete [] buf; 278 | } 279 | } 280 | pConverter->Release(); 281 | } 282 | pBitmap->Release(); 283 | } 284 | return true; 285 | } 286 | static HICON extract_file_icon(const String& file_path) { 287 | SHFILEINFOW file_info = { 0 }; 288 | HIMAGELIST hfi = (HIMAGELIST)::SHGetFileInfo(file_path.c_str(), 0, &file_info, sizeof(SHFILEINFOW), SHGFI_SYSICONINDEX); 289 | return ::ImageList_GetIcon(hfi, file_info.iIcon, ILD_NORMAL); 290 | } 291 | 292 | private: 293 | bool fill_bitmap(void* bytes, int byte_count) { 294 | Byte* buf = 0; 295 | if (!create_bitmap(info_header.biWidth, info_header.biHeight, (void**)(&buf), &hBmp)) { 296 | return false; 297 | } 298 | memcpy(buf, bytes, byte_count); 299 | return bits.load(bytes, byte_count); 300 | } 301 | static bool create_bitmap(int width, int height, void** bits, HBITMAP* phBmp) { 302 | BITMAPINFO bmi = { 0 }; 303 | bmi.bmiHeader = create_info_header(width, height); 304 | *phBmp = ::CreateDIBSection(GetDC(0), &bmi, DIB_RGB_COLORS, bits, 0, 0); 305 | return *phBmp != 0; 306 | } 307 | }; 308 | 309 | struct Cache { 310 | 311 | struct Item { 312 | String name; 313 | Bmp bmp; 314 | 315 | bool create(const String& file_name, const String& file_path) { 316 | if (!Bmp::convert_file_icon(Bmp::extract_file_icon(file_path), bmp)) { 317 | return false; 318 | } 319 | name = file_name; 320 | return true; 321 | } 322 | void serialize(Buffer& buffer) { 323 | buffer.load(name, true); 324 | bmp.serialize(buffer); 325 | } 326 | void unserialize(Buffer& buffer, size_t& pos) { 327 | name = (Char*)(buffer.data + pos); pos += (name.size() + 1) * sizeof(Char); 328 | bmp.load_bits_and_headers(buffer.data + pos); pos += bmp.total_size(); 329 | } 330 | }; 331 | 332 | 333 | std::vector items; 334 | int fixed_items; 335 | bool was_rebuilt; 336 | 337 | Cache(const String& stack_path) : last_modified(0), was_rebuilt(false), scanned_last_modified(0), fixed_items(0) { 338 | base_dir = Util::trim(Util::rtrim(stack_path, DIR_SEP), L"\"") + DIR_SEP; 339 | cache_path = path(CACHE_FILE_NAME); 340 | } 341 | 342 | String path(const String& file = L"") const { 343 | return base_dir + file; 344 | } 345 | bool scan() { 346 | WIN32_FIND_DATA ffd = { 0 }; 347 | HANDLE hfind = FindFirstFile(path(L"*").c_str(), &ffd); 348 | if (hfind == INVALID_HANDLE_VALUE) { 349 | return false; 350 | } 351 | do { 352 | String filename = ffd.cFileName; 353 | if (filename == L"." || filename == L".." || ffd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) 354 | continue; 355 | scanned_items.push_back(filename); 356 | update_max_modified(filename); 357 | } 358 | while (FindNextFile(hfind, &ffd) != 0); 359 | return true; 360 | } 361 | bool load() { 362 | Buffer buffer; 363 | items.clear(); 364 | 365 | buffer.load(cache_path); 366 | for (size_t pos = 0; pos < buffer.size; ) { 367 | Item item; 368 | item.unserialize(buffer, pos); 369 | items.push_back(item); 370 | } 371 | last_modified = Util::get_modified(cache_path); 372 | 373 | if (is_outdated()) { 374 | rebuild(); 375 | was_rebuilt = true; 376 | } 377 | 378 | return true; 379 | } 380 | 381 | private: 382 | String base_dir; 383 | String cache_path; 384 | Time last_modified; 385 | StringList scanned_items; 386 | Time scanned_last_modified; 387 | 388 | bool rebuild() { 389 | Buffer buffer; 390 | items.clear(); 391 | 392 | Item item; 393 | item.create(L"Open: " + Util::rtrim(path(), DIR_SEP), path()); 394 | item.serialize(buffer); 395 | items.push_back(item); 396 | for (size_t i = 0; i < scanned_items.size(); i++) { 397 | String file_name = scanned_items[i]; 398 | item.create(file_name, path(file_name)); 399 | item.serialize(buffer); 400 | items.push_back(item); 401 | } 402 | 403 | save(buffer); 404 | return true; 405 | } 406 | void save(Buffer buffer) { 407 | ::DeleteFile(cache_path.c_str()); 408 | buffer.save(cache_path); 409 | ::SetFileAttributes(cache_path.c_str(), FILE_ATTRIBUTE_HIDDEN); 410 | } 411 | void update_max_modified(const String& filename) { 412 | Time ft = Util::get_modified(path(filename)); 413 | scanned_last_modified = scanned_last_modified < ft ? ft : scanned_last_modified; 414 | } 415 | bool is_outdated() { 416 | if (scanned_last_modified > last_modified || items.size() < 1 || scanned_items.size() + 1 != items.size()) { 417 | return true; 418 | } 419 | for (size_t i = 0; i < scanned_items.size(); i++) if (scanned_items[i] != items[i + 1].name) { 420 | return true; 421 | } 422 | return false; 423 | } 424 | }; 425 | 426 | /************************************************************************************************** 427 | * The app 428 | **************************************************************************************************/ 429 | struct App { 430 | 431 | App(Cache* c) : cache(c), window(0) { } 432 | 433 | bool init() { 434 | // Create window 435 | Util::kill_other_stackies(); 436 | WNDCLASS wc = { 0 }; 437 | wc.style = CS_HREDRAW | CS_VREDRAW; 438 | wc.lpfnWndProc = window_proc; 439 | wc.hInstance = ::GetModuleHandle(0); 440 | wc.lpszClassName = STACKY_WINDOW_NAME; 441 | if (!::RegisterClass(&wc)) { 442 | return false; 443 | } 444 | window = ::CreateWindow(STACKY_WINDOW_NAME, STACKY_WINDOW_NAME, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, 0, 0, ::GetModuleHandle(0), 0); 445 | ::SetWindowLongPtr(window, GWLP_USERDATA, (LONG_PTR)cache); 446 | 447 | // Create window 448 | HMENU menu = ::CreatePopupMenu(); 449 | cache->fixed_items = 1; 450 | add_item(menu, 0, WM_OPEN_TARGET_FOLDER, cache->items[0]); 451 | if (cache->was_rebuilt) { 452 | cache->fixed_items = 2; 453 | add_separator(menu, L"Stack cache rebuilt!"); 454 | } 455 | add_separator(menu, L""); 456 | for (size_t i = 1; i < cache->items.size(); i++) { 457 | Cache::Item& item = cache->items[i]; 458 | add_item(menu, (int)i + cache->fixed_items, WM_MENU_ITEM, item); 459 | } 460 | show(menu); 461 | return true; 462 | } 463 | void run() { 464 | for (MSG msg; ::GetMessage(&msg, 0, 0, 0); ) { 465 | ::TranslateMessage(&msg); 466 | ::DispatchMessage(&msg); 467 | } 468 | } 469 | 470 | private: 471 | HWND window; 472 | Cache* cache; 473 | 474 | bool add_separator(HMENU hMenu, const String& text) { 475 | return AppendMenu(hMenu, text.empty() ? MF_SEPARATOR : MF_GRAYED, 0, text.c_str()) == TRUE; 476 | } 477 | bool add_item(HMENU hMenu, int idx, int msg, const Cache::Item& item) { 478 | MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; 479 | mii.fMask = MIIM_BITMAP; 480 | mii.hbmpItem = item.bmp.hBmp; 481 | ::AppendMenu(hMenu, MF_STRING, msg + idx, Util::rtrim(item.name, L".lnk").c_str()); 482 | return SUCCEEDED(::SetMenuItemInfo(hMenu, idx, TRUE, &mii)); 483 | } 484 | void show(HMENU menu) { 485 | RECT rWorkArea; 486 | POINT pos; 487 | ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rWorkArea, 0); 488 | ::GetCursorPos(&pos); 489 | 490 | LONG pos_x = pos.x, pos_y = pos.y; 491 | if (pos_x < rWorkArea.left) pos_x = rWorkArea.left - 1; 492 | else if (pos_x > rWorkArea.right) pos_x = rWorkArea.right - 1; 493 | if (pos_y < rWorkArea.top) pos_y = rWorkArea.top - 1; 494 | else if (pos_y > rWorkArea.bottom) pos_y = rWorkArea.bottom - 1; 495 | 496 | ::SetForegroundWindow(window); 497 | ::TrackPopupMenuEx(menu, ::GetSystemMetrics(SM_MENUDROPALIGNMENT) | TPM_LEFTBUTTON, pos_x, pos_y, window, 0); 498 | } 499 | static LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { 500 | switch (msg) { 501 | case WM_COMMAND: { 502 | Cache* cache = (Cache*)::GetWindowLongPtr(hwnd, GWLP_USERDATA); 503 | String cmd = cache->path(wparam == WM_OPEN_TARGET_FOLDER ? L"" : cache->items[wparam - WM_MENU_ITEM - cache->fixed_items].name); 504 | ::ShellExecute(0, 0, cmd.c_str(), 0, 0, SW_NORMAL); 505 | } 506 | case WM_EXITMENULOOP: 507 | // WM_EXITMENULOOP is sent before WM_COMMAND, so the app termination has to be delayed. 508 | // This also allows to wait for the possible UAC prompt. 509 | ::SetTimer(hwnd, 0, APP_EXIT_DELAY, 0); 510 | break; 511 | case WM_TIMER: 512 | ::PostQuitMessage(0); 513 | ::DestroyWindow(hwnd); 514 | break; 515 | } 516 | return ::DefWindowProc(hwnd, msg, wparam, lparam); 517 | } 518 | }; 519 | 520 | /************************************************************************************************** 521 | * App entry point 522 | **************************************************************************************************/ 523 | int WINAPI wWinMain(HINSTANCE inst, HINSTANCE, LPTSTR cmd_line, int) { 524 | String stack_path, opts; 525 | int cmd_line_error = Util::parse_cmd_line(cmd_line, stack_path, opts); 526 | String err_title = String(L"Stacky v") + STACKY_VERSION_STR + L": "; 527 | String err_msg = L"Path: " + stack_path; 528 | 529 | Cache cache(stack_path); 530 | App app(&cache); 531 | 532 | if (cmd_line_error == ERR_PATH_MISSING) Util::msgt(err_title + L"Parameter missing", L"Pass path to the stack folder in the command line, for ex.: \n\n stacky.exe D:\\Projects"); 533 | else if (cmd_line_error == ERR_PATH_INVALID) Util::msgt(err_title + L"Invalid parameter", (L"Path: " + stack_path + L" is not a valid directory").c_str()); 534 | else if (!cache.scan()) Util::msgt(err_title + L"Invalid path", err_msg); 535 | else if (!cache.load()) Util::msgt(err_title + L"Failed to load stack cache", err_msg); 536 | else if (!app.init()) Util::msgt(err_title + L"App init failed", err_msg); 537 | else app.run(); 538 | return 0; 539 | } 540 | --------------------------------------------------------------------------------