Skip to content

Commit 3bb157c

Browse files
committed
Update AutopatcherServerTest.cpp
1 parent 0df4dcc commit 3bb157c

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

Samples/AutopatcherServer/AutopatcherServerTest.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
// Common includes
1717
#include <stdio.h>
1818
#include <stdlib.h>
19+
20+
#ifdef _WIN32
21+
#include <windows.h>
22+
#include <shellapi.h>
23+
#else
24+
#include <limits.h>
25+
#include <cerrno>
26+
#ifndef MAX_PATH
27+
#define MAX_PATH PATH_MAX
28+
#endif
29+
#endif
30+
1931
#include "mafianet/Kbhit.h"
2032

2133
#include "mafianet/GetTime.h"
@@ -74,24 +86,21 @@ class AutopatcherPostgreRepository2_WithXDelta : public MafiaNet::AutopatcherPos
7486
}
7587
else
7688
{
89+
#ifdef _WIN32
7790
*patchAlgorithm=1;
7891
fclose(fpOld);
7992
fclose(fpNew);
8093

8194
char buff[128];
8295
MafiaNet::TimeUS time = MafiaNet::GetTimeUS();
83-
#if defined(_WIN32)
8496
sprintf_s(buff, "%I64u", time);
85-
#else
86-
sprintf_s(buff, "%llu", (long long unsigned int) time);
87-
#endif
8897

8998
// Invoke xdelta
9099
// See https://code.google.com/p/xdelta/wiki/CommandLineSyntax
91100
char commandLine[512];
92101
_snprintf(commandLine, sizeof(commandLine)-1, "-f -s %s %s patchServer_%s.tmp", oldFile, newFile, buff);
93102
commandLine[511]=0;
94-
103+
95104
SHELLEXECUTEINFOA shellExecuteInfo;
96105
shellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFOA);
97106
shellExecuteInfo.fMask = SEE_MASK_NOASYNC | SEE_MASK_NO_CONSOLE;
@@ -138,6 +147,14 @@ class AutopatcherPostgreRepository2_WithXDelta : public MafiaNet::AutopatcherPos
138147
}
139148

140149
return 0;
150+
#else
151+
// xdelta not supported on non-Windows, use bsdiff for large files
152+
*patchAlgorithm=0;
153+
bool b = MakePatchBSDiff(fpOld, contentLengthOld, fpNew, contentLengthNew, patch, patchLength);
154+
fclose(fpOld);
155+
fclose(fpNew);
156+
return b==false ? -1 : 0;
157+
#endif
141158
}
142159
}
143160
};
@@ -210,6 +227,7 @@ int main(int, char **)
210227
// autopatcherServer.SetAllowDownloadOfOriginalUnmodifiedFiles(false);
211228
printf("System ready for connections\n");
212229

230+
#ifdef _WIN32
213231
// https://code.google.com/p/xdelta/downloads/list
214232
printf("Optional: Enter path to xdelta.exe: ");
215233
Gets(PATH_TO_XDELTA_EXE, sizeof(PATH_TO_XDELTA_EXE));
@@ -225,6 +243,11 @@ int main(int, char **)
225243
if (WORKING_DIRECTORY[strlen(WORKING_DIRECTORY)-1]=='\\' || WORKING_DIRECTORY[strlen(WORKING_DIRECTORY)-1]=='/')
226244
WORKING_DIRECTORY[strlen(WORKING_DIRECTORY)-1]=0;
227245
}
246+
#else
247+
// xdelta not supported on non-Windows platforms
248+
PATH_TO_XDELTA_EXE[0] = 0;
249+
WORKING_DIRECTORY[0] = 0;
250+
#endif
228251

229252
printf("(D)rop database\n(C)reate database.\n(A)dd application\n(U)pdate revision.\n(R)emove application\n(Q)uit\n");
230253

0 commit comments

Comments
 (0)