2010年7月20日 星期二

專案自動化建置(先叫這個名字)

這是我轉寫的批次檔
主要功能是將Qt的專案編譯成執行檔
再轉成安裝程式(unicode nsis)
最後上傳到伺服器

資料夾說明
code放qt的專案和程式碼
bin編譯完成後的執行檔和obj file
resource執行時需要的圖檔或文字檔
install-win安裝程式原始碼和檔案
CD-win光碟檔

下面是批次檔
rem 移除一些不需要的檔案(win和mac以及qt的暫存檔)
del .* /a/s/f/q
del Thumbs.db /a/s/f/q
del *.o /a/s/f/q
del *.db /a/s/f/q
del *.DS_Store /a/s/f/q
del *.pro.user /a/s/f/q
del Makefile /a/s/f/q
del *.Debug /a/s/f/q
del *.bak /a/s/f/q
del *.Release /a/s/f/q
del moc_*.cpp /a/s/f/q
rem 移除執行檔(因為要重新編譯)
rd bin /s /Q

rem 建立版本(利用日期),分別放到version.h和version.nsi,這樣執行檔和安裝程式就有相同的版本
For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set date=%%a-%%b-%%c)
echo #define VERSION "%date%">Code/version.h
echo !define SOURCE_FILE_VERSION "%date%">install-win\version.nsi

rem 編譯qt專案成執行檔
call C:\Qt\2010.04\bin\qtenv.bat
cd Code
qmake
mingw32-make release
cd ..

rem 建立安裝檔,先將光碟檔移除(因為將重新編譯)
rd CD-win /s /Q
rem 將執行檔需要的檔案複製到file
xcopy install-win\File-template\*.* install-win\File\ /Y /S
XCOPY Resource\*.* install-win\File\ /Y
COPY "bin\release\MySoftWare\MySoftWare.exe" "install-win\File\MySoftWare.exe"
rem 將光碟需要的檔案複製到CD-win
XCOPY install-win\CD-template\*.* CD-win\ /Y /S
rem 編譯安裝檔(請自行尋找nsis),產生setup.exe
call "C:\Program Files\NSIS\Unicode\makensis.exe" "install-win\setup.nsi"
rem 移除File(因為安裝檔已經產生)
rd install-win\File /s /Q
COPY "install-win\setup.exe" "CD-win\setup.exe"

rem 上傳到伺服器
cd install-win
rem 壓縮安裝檔成zip(zip.exe是利用info-zip)
zip setup.zip setup.exe
cd..
set FTPActions=00000000000000.FTP
echo open your.web.ip>>%FTPActions%
echo namen>>%FTPActions%
echo password>>%FTPActions%
echo cd /web.com/download/MySoftWare>>%FTPActions%
echo mkdir %date%>>%FTPActions%
echo cd %date%>>%FTPActions%
echo bin>>%FTPActions%
echo send install-win\setup.zip setup.zip>>%FTPActions%
echo bye>>%FTPActions%
ftp -s:%FTPActions%
del %FTPActions%

rem 利用php解壓縮
start http://www.web.com/download/MySoftWare/unzip.php?path=%date%

pause


下面這一段式是unzip.php
<?php
$zip = zip_open($path."/setup.zip");
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$fp = fopen($path."/".zip_entry_name($zip_entry), "w");
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
fwrite($fp,"$buf");
zip_entry_close($zip_entry);
fclose($fp);
}
}
zip_close($zip);
echo ‘ok’;
} else {
echo ‘failed’;
}
?>

2010年6月22日 星期二

print bitmap font array

先定義一下bitmap格式方便之後處裡
typedef struct Bitmap_ {
    int             x;
    int             y;
    unsigned int    width;
    unsigned int    height;
    unsigned int    pitch;
    unsigned char*  data;

} Bitmap;
下面是完整的程式,執行後將列印出一個大寫的F

#include <stdlib.h>
#include <stdio.h>
#include <locale.h>

typedef struct Bitmap_ {
    int             x;
    int             y;
    unsigned int    width;
    unsigned int    height;
    unsigned int    pitch;
    unsigned char*  data;

} Bitmap;

void printtext(Bitmap *bitmap)
{
    for(int j=0; j<bitmap->height; j++) {
        for(int i=0; i<bitmap->pitch; i++) {
            for(int k=7; k>=0; k--) {
                if(7-k+i*8 == bitmap->width)
                    break;
                wprintf(L"%c", (bitmap->data[i+j*bitmap->pitch] & 0x1<<k)?L'■':L'□');
            }
        }
        printf("\n");
    }
}

int main(int argc, char *argv[])
{
    if (!setlocale(LC_CTYPE, "")) {
        return EXIT_FAILURE;
    }

    unsigned char rasters[24] = { 0xff,0xc0,
                                  0xff,0xc0,
                                  0xc0,0x00,
                                  0xc0,0x00,
                                  0xc0,0x00,
                                  0xff,0x00,
                                  0xff,0x00,
                                  0xc0,0x00,
                                  0xc0,0x00,
                                  0xc0,0x00,
                                  0xc0,0x00,
                                  0xc0,0x00
                                };

    Bitmap bitmap = {0, 0, 10, 12, 2, rasters};
    printtext(&bitmap);
    return EXIT_SUCCESS;
}

2010年3月30日 星期二

專案交接

1.建置環境
必須建立實作一套可以在命令列下完成 init, build, package, install, test 動作的建置程序,並且包涵需要之套件軟體。視專案內容,這套建置程序可能是一份 build.xml(ant), 也可能是一份 Makefile ,或是更基礎的 shell script。重點是,這套建置程序要能交由建置系統自動執行並完成上述所有動作,整個過程不可以有人工輸入的部份。

2.環境說明文件
必須說明專案以及所需套件軟體和函式庫的用途。

3.專案uml圖

4.程式碼文件
開頭必須作文件簡介,及各函式簡介和修改紀錄
函式前必須詳細說明函式功能,包涵輸入及輸出說明


參考資料

2010年1月24日 星期日

如何在建立windows執行檔的版本資訊

打開rc檔
加入
VALUE "CompanyName", "公司\0"
VALUE "FileVersion", "檔案版本\0"
VALUE "FileDescription", "描述\0"
VALUE "InternalName", "內部名稱\0"
VALUE "LegalCopyright", "著作權\0"
VALUE "LegalTrademarks", "合法商標\0"
VALUE "OriginalFilename", "原始檔名\0"
VALUE "ProductName", "產品名稱\0"
VALUE "ProductVersion", "產品版本\0"
VALUE "Comments", "註解\0"
斷行要用\r\n

2010年1月6日 星期三

Wheel Light 模擬器

這是最近替公司產品寫的模擬器。主要是用Qt+OpenGL寫出來的。
有美工人員就是不一樣^.^

2009年11月13日 星期五

Qt 專案管理

假設有一個母專案MyWholeApp
其中有一個子專案在子資料夾DummyDlg中

在DummyDlg中
建立一檔案名為DummyDlg.pri
其中內容為
FORMS += $$PWD/dummydlg.ui
HEADERS += $$PWD/dummydlg.h
SOURCES += $$PWD/dummydlg.cpp

修改專案檔DummyDlg.pro
TEMPLATE = app
DEPENDPATH += .
INCLUDEPATH += .
include(DummyDlg.pri)
# Input
SOURCES += main.cpp

這樣子專案就建立完成了

至於母專案如何利用子專案
WholeApp.pro
TEMPLATE = app
DEPENDPATH += . DummyDlg
INCLUDEPATH += . DummyDlg
include(DummyDlg/DummyDlg.pri)
# Input
FORMS += OtherDlg.ui
HEADERS += OtherDlg.h
SOURCES += OtherDlg.cpp
WholeApp.cpp