/* Copyright 2016 Grady Moran Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include #include #include #include #include int main() { WIN32_FIND_DATA parent_wabbit_data; WIN32_FIND_DATA baby_wabbit_data; TCHAR my_path[MAX_PATH]; //string of full path, including filename TCHAR my_folder[MAX_PATH]; GetModuleFileName(NULL, my_path, sizeof(my_path)/sizeof(*my_path) ); HANDLE findWabbit = FindFirstFile(TEXT(my_path), &parent_wabbit_data); if (findWabbit == INVALID_HANDLE_VALUE) { return 1; } else { /* * The number of rabbits tends towards too many as clicks -> + infinity */ strcpy(my_folder, my_path); my_folder[strrchr(my_path, 92) - my_path + 1] = '\0'; /* leaves runes at end of string if you use strncpy instead of manually setting the \0. statement inside [] returns first index after exe's parent folder (92 is ascii \) */ //loop through folder checking whether wabbit1, wabbit3, wabbit4, etc exist. The first one that doesn't is filename to copy to. int this_wabbit = 1; TCHAR baby_wabbit_name[MAX_PATH]; HANDLE find_baby_wabbit_location; char tmpstr[10]; //holds string version of this_wabbit do { strcpy(baby_wabbit_name, my_folder); strcat(baby_wabbit_name, "wabbit"); sprintf(tmpstr, "%d", this_wabbit); strcat(baby_wabbit_name, tmpstr); strcat(baby_wabbit_name, ".exe"); find_baby_wabbit_location = FindFirstFile(TEXT(baby_wabbit_name), &baby_wabbit_data); this_wabbit++; } while (find_baby_wabbit_location != INVALID_HANDLE_VALUE); if (!CopyFile(parent_wabbit_data.cFileName, baby_wabbit_name, FALSE)){ //fprintf(stderr, "unfortunately, not all wabbits successfully find a mate\n"); return 2; } } return 0; }