Removed third party tools, they all are placed in http://github.com/mangosthree/tools

This commit is contained in:
sanctum32 2013-12-20 04:47:44 +02:00 committed by Antz
parent 4ce27abad6
commit 484a468f1a
35 changed files with 0 additions and 4784 deletions

View file

@ -1,243 +0,0 @@
#!/bin/sh
# This code is part of MaNGOS. Contributor & Copyright details are in AUTHORS/THANKS.
# This program is free software licensed under GPL version 2
# Please see the included COPYING for full text */
###############################################################################
#
# Simple helper script to help merging branches & pull requests
#
###############################################################################
#internal use
script_file_name="MergeHelper.sh"
config_file_name="_MergeHelper.config"
base_dir=${0%[/\\]*}
config_file=$base_dir/$config_file_name
DEBUG=0
no_ff_merge="--no-ff"
# #############################################################################
# Helper functions
# #############################################################################
# Re(create) the config file
function create_config {
cat > $config_file << EOF
###############################################################################
# This is the config file for the '$script_file_name' script
#
# The format to automatically merge (and fetch) remote branches is
# repo/branch
# repo2/branch2
#
# The format to automatically merge local branches is
# branch1
# branch2
#
# The format to automatically merge (and fetch) pull requests is
# remote#PullRequestNumber1
# remote#PullRequestNumber2
#
###############################################################################
# Which remote branches should be fetched and merged?
# Format to automatically fetch from a repo and merge the branch: <repo/branch>
# Example:
#origin/master
# Which local branches should be merged?
# Format to automatically merge a local branch: <branchName>
#some_cool_feature
# Which pull requests shall be merged from a repo?
# Format to automatically fetch and merge a pull request: <Repo#NumberOfPullRequest>
# Example:
#origin#17
# Enjoy using the tool
EOF
}
# #############################################################################
# Display help
function display_help {
echo
echo "Welcome to the MaNGOS merge helper $script_file_name"
echo
echo "Run this tool from a bash compatible terminal (on windows like Git Bash)"
echo
echo "To configure edit the file \"$config_file\""
echo
echo "Supported options are"
echo " -h -- displays the help you currently see"
echo " -c -- specify config file (Default: $base_dir/$config_file_name )"
echo " -r -- change the remote from which you want to merge a pull-request"
echo " -l -- list available pull-requests from the remote (by default from origin)"
echo " -f -- do fast forward merges if possible (default: do not use fast-forward merges)"
echo
echo "Supported parameters are"
echo " XX -- Number which pull-reqest to merge"
echo " (Default PR pulled from origin, the remote can be changed with -r option"
echo
}
# #############################################################################
# Function to fetch and merge a pull reqest
# Call with param1 == remote, param2 == Number
function merge_pull_request {
echo "Now fetching and merging pull-request $2 (from remote $1)"
git fetch $1 +refs/pull/$2/head:refs/remotes/$1/pr/$2
[[ $? != 0 ]] && exit 1
git merge $no_ff_merge $1/pr/$2
[[ $? != 0 ]] && exit 1
}
# #############################################################################
# Main Method
# #############################################################################
# Must have Git available
git rev-parse --git-dir 1>/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "ERROR: This script must be used within a Git working tree"
echo "Try to start from your main mangos directory by using"
echo " \"contrib/$script_file_name\""
read -p"Press [RETURN] to exit"
exit 1
fi
# Config options
pull_remote="origin"
do_help=0
do_list=0
while getopts ":hc:r:lf" opt; do
case $opt in
h)
do_help=1
;;
c)
config_file=$OPTARG
echo "Using configuration file $config_file"
;;
r)
pull_remote=$OPTARG
echo "Using remote $pull_remote for parameter pull-request merge"
;;
l)
do_list=1
;;
f)
no_ff_merge=""
;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
;;
:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
esac
done
shift $((OPTIND-1))
# Display help and exit
if [ $do_help -eq 1 ]; then
display_help
if [ ! -f $config_file ]; then
create_config
fi
exit 0
fi
# List remotes and exit
if [ $do_list -eq 1 ]; then
echo "Available Pull-Requests on remote $pull_remote:"
git ls-remote $pull_remote pull/*/head | sed 's;.*refs/pull/\([0-9]*\)/head; \1;g'
exit 0
fi
# Called with Pull Request for direct merge
if [ "$1" != "" ]; then
# Alternate call with pull-request number
merge_pull_request $pull_remote $1
exit 0
fi
# Check if config file present
if [ ! -f $config_file ]
then
create_config
display_help
read -p"Press [RETURN] to exit"
exit 1
fi
already_fetched_remotes=""
# The config file exists, read it line by line and use its content
while read cline
do
if [ $DEBUG -eq 1 ]; then echo "DEBUG - Processing line $cline"; fi
# Non-empty and non-comment line (comments start with #)
if [[ "$cline" != "" && "$cline" != \#* ]]; then
if echo $cline | egrep -s "^([[:alnum:]_-]+)#([[:digit:]]+)$" ; then
# Pull-Request found - Format is <remote#number>
remote=`echo $cline | sed -r 's@([[:alnum:]_-]+)#([[:digit:]]+)@\1@'`
PR=`echo $cline | sed -r 's@([[:alnum:]_-]+)#([[:digit:]]+)@\2@'`
if [ $DEBUG -eq 1 ]; then echo "DEBUG - pull request line found (remote $remote PR $PR)"; fi
merge_pull_request $remote $PR
elif echo $cline | egrep -s "^([[:alnum:]_-]+)/([[:alnum:]_-]+)$" ; then
# remote branch found - Format is <remote/branch>
remote=`echo $cline | sed -r 's@([[:alnum:]_-]+)/([[:alnum:]_-]+)@\1@'`
branch=`echo $cline | sed -r 's@([[:alnum:]_-]+)/([[:alnum:]_-]+)@\2@'`
if [ $DEBUG -eq 1 ]; then echo "DEBUG - remote branch line found (remote $remote branch $branch)"; fi
found_remote=0
for f in $already_fetched_remotes; do
if [ "$f" = "$remote" ]; then
found_remote=1
fi
done
if [ $found_remote -eq 0 ]; then
already_fetched_remotes="$already_fetched_remotes $remote"
echo "Fetching $remote"
git fetch $remote
[[ $? != 0 ]] && exit 1
fi
echo "Merging $branch from $remote"
git merge $no_ff_merge $remote/$branch
[[ $? != 0 ]] && exit 1
elif echo $cline | egrep -s "^([[:alnum:]_-]+)$" ; then
# local branch found - Format is <branchName>
branch=`echo $cline | sed -r 's@([[:alnum:]_-]+)@\1@'`
if [ $DEBUG -eq 1 ]; then echo "DEBUG - local branch line found (branch $branch)"; fi
git merge $no_ff_merge $branch
[[ $? != 0 ]] && exit 1
else
echo "Unsupported config line found: $cline"
echo "Aborting..."
exit 1
fi
fi
done < $config_file
echo
echo "All done."
echo
exit 0

View file

@ -1,333 +0,0 @@
#!/bin/bash
#
# mangos-backport - a bash helper for backporting in git for MaNGOS project
# Copyright (C) 2009 freghar <compmancz@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA
#
# The script works pretty simple - each time an empty commit is made,
# copying author and message from the original one.
# Then the original commit is cherry-picked -n (no commit)
# and the changes are git commit --amended to the prepared empty commit.
### general definitions
## internals
BATCH_PROCESS=0
VERBOSE=0
## user-tunable
AUTORESOLVE="src/shared/revision_nr.h"
GIT_AMEND_OPTS="-s"
GIT_RECOVER="git reset --hard HEAD^"
CONFLICT_RETVAL=2 # for batch usage
GIT_PATH="./"
### print error to stderr
function print_error {
echo -e "${@}" 1>&2
}
### prints help
function print_help {
echo -e "Usage: ${0##*/} [-vb] <revspec>" \
"\nBackports a specified commit to current branch." \
"\n\n -b Batch processing (no interaction)." \
"\n (runs amend without calling \$EDITOR)" \
"\n -v Be verbose." \
"\n -n Never automatically commit." \
"\n"
}
### verbose print
function verbose_print {
[[ ${VERBOSE} > 0 ]] && echo "${@}"
}
### runs a command and handles it's output verbosity
#function verbose_run {
# if [[ ${VERBOSE} > 0 ]]; then
# "${@}"
# return $?
# else
# "${@}" 1 > /dev/null
# return $?
# fi
#}
### catches output of a command and returns it's retval
#function catch_out {
# pick_out=$(${@} 2>&1)
# return $?
#}
### recover from an error, deleting empty commit
function git_recover {
print_error "----------"
print_error "Caught an error, checking for last commit ..."
# check if the last commit is empty,
# ie. it has the same tree object dependency as it's parent
local head_tree=$(git log -1 --pretty="%T" HEAD)
local prev_tree=$(git log -1 --pretty="%T" HEAD^)
if [[ $head_tree == $prev_tree ]]; then
print_error "Last commit empty, running ${GIT_RECOVER}" \
"\nto previous HEAD (should be ${CURRENT_HEAD})."
print_error "----------"
${GIT_RECOVER}
else
print_error "Last commit isn't empty (or git log failed) -" \
"something strange happened,\ncheck git log" \
"and do the cleanup (if needed) by hand."
fi
exit 1
}
### amend the empty commit, assigning new tree
function git_autoamend {
# if the index is empty, there's nothing to amend
if [[ -z $(git diff-index --cached HEAD) ]]; then
git_retval=$?
[[ $git_retval != 0 ]] && git_recover
print_error "The index is empty, nothing to amend. This should" \
"not happen during normal\nworkflow, so you" \
"probably did something crazy like picking\na" \
"commit to a branch where it already exists."
git_recover
fi
verbose_print "----------"
if [[ ${BATCH_PROCESS} > 0 ]]; then
if [[ ${VERBOSE} > 0 ]]; then
git commit ${GIT_AMEND_OPTS} --amend -C HEAD
git_retval=$?
else
git commit ${GIT_AMEND_OPTS} --amend -C HEAD 1> /dev/null
git_retval=$?
[[ $git_retval == 0 ]] && echo \
"Commit ${COMMIT_HASH} picked."
fi
else
git commit ${GIT_AMEND_OPTS} --amend -c HEAD
git_retval=$?
fi
[[ $git_retval != 0 ]] && git_recover
}
### main()
## arguments
# arg parsing
while getopts "vbn" OPTION; do
case $OPTION in
v)
VERBOSE=1
;;
b)
BATCH_PROCESS=1
;;
n)
NO_AUTOCOMMIT=1
;;
\?)
print_help
exit 1
;;
esac
done;
shift $(( $OPTIND - 1 ))
ORIG_REF=${1}
# check for needed arguments
if [[ -z ${ORIG_REF} ]]; then
print_help
exit 1
fi
## startup checks
# check for needed commands
for cmd in git grep sed wc; do
if [[ -z $(which ${cmd}) ]]; then
print_error "error: ${cmd}: command not found"
exit 1
fi
done;
# are we in git root dir?
if [[ ! -d .git/ ]]; then
print_error "error: not in repository root directory"
exit 1
fi
# is the index clean?
if [[ ! -z $(git diff-index HEAD) ]]; then
print_error "error: dirty index, run mixed/hard reset first"
exit 1
fi
## original commit infos
# current HEAD commit hash
CURRENT_HEAD=$(git show -s --pretty=format:'%h' HEAD)
[[ $? != 0 ]] && exit 1
# author with email
COMMIT_AUTHOR=$(git show -s --pretty=format:'%an <%ae>' ${ORIG_REF})
[[ $? != 0 ]] && exit 1
# commit object hash (abbrev)
COMMIT_HASH=$(git show -s --pretty=format:'%h' ${ORIG_REF})
[[ $? != 0 ]] && exit 1
# subject (with removed revision number)
COMMIT_SUBJECT=$(git show -s --pretty=format:'%s' ${ORIG_REF} | sed -r 's/\[[a-z]?[0-9]*\] //')
[[ $? != 0 ]] && exit 1
COMMIT_REVISION=$(git show -s --pretty=format:'%s' ${ORIG_REF} | sed -nr 's/^\[([a-z]?[0-9]*).*/\1/p')
[[ $? != 0 ]] && exit 1
if [ "$COMMIT_REVISION" != "" ]; then COMMIT_REVISION="[$COMMIT_REVISION] - "; fi
# body
COMMIT_BODY=$(git show -s --pretty=format:'%b' ${ORIG_REF})
[[ $? != 0 ]] && exit 1
# whole message (yea, it could be done without echo)
COMMIT_MESSAGE=$(echo -e "${COMMIT_SUBJECT}\n\n${COMMIT_BODY}\n\n(based on commit $COMMIT_REVISION${COMMIT_HASH})")
[[ $? != 0 ]] && exit 1
## new empty commit ready, so create it
verbose_print "Creating new empty commit on current HEAD (${CURRENT_HEAD}}."
verbose_print "----------"
if [[ ${VERBOSE} > 0 ]]; then
git commit --author="${COMMIT_AUTHOR}" -m "${COMMIT_MESSAGE}" \
--allow-empty
[[ $? != 0 ]] && exit 1
else
git commit --author="${COMMIT_AUTHOR}" -m "${COMMIT_MESSAGE}" \
--allow-empty 1> /dev/null
[[ $? != 0 ]] && exit 1
fi
## first, try cherry-picking the commit and catch conflicts.
## - if there are none, simply amend and exit
## - if there are none related to $AUTORESOLVE, only prepare
## the backported commit
## - when multiple conflicts occur, including $AUTORESOLVE,
## do the resolution for the one file, prepare the commit
## and let user resolve the rest (+ amend)
## - when only single ($AUTORESOLVE) conflict occur, resolve it
## and fire up $EDITOR to autocommit
pick_out=$(git cherry-pick -n ${ORIG_REF} 2>&1)
pick_retval=$?
# exit if there was a fatal app error
if [[ $pick_retval > 1 ]]; then
print_error "${pick_out}"
git_recover
fi
# get a list of unmerged files
unmerged_files=$(git diff-files --diff-filter=U | sed 's/^[^\t]*\t//')
git_retval=$?
if [[ $git_retval != 0 ]]; then
print_error "${pick_out}"
git_recover
fi
# simply amend if the pick was successful
if [[ $pick_retval == 0 && -z $unmerged_files ]]; then
verbose_print "${pick_out}"
verbose_print "----------"
if [[ ${NO_AUTOCOMMIT} > 0 ]]; then
verbose_print "No conflicts to resolve, nothing to do."
verbose_print "Please run git commit ${GIT_AMEND_OPTS} --amend" \
"after making all necessary changes."
verbose_print "Use ${GIT_RECOVER} to recover."
else
verbose_print "No conflicts to resolve, running amend."
git_autoamend
fi
exit 0
fi
# sanity check
if [[ -z $unmerged_files ]]; then
print_error "${pick_out}"
print_error "----------"
print_error "git cherry-pick failed with status 1," \
"\nbut no unmerged files were found."
git_recover
fi
# if $AUTORESOLVE isn't there (but other conflicts are), simply exit
if [[ -z $(echo "${unmerged_files}" | grep ${AUTORESOLVE}) ]]; then
print_error "${pick_out}"
echo "----------"
verbose_print "${AUTORESOLVE} not found as unmerged."
echo "Please run git commit ${GIT_AMEND_OPTS} --amend" \
"after resolving all conflicts."
echo "To recover from the resolution, use ${GIT_RECOVER}."
exit ${CONFLICT_RETVAL}
fi
# do the resolution - use old version of the file
if [[ -f ${AUTORESOLVE} ]]; then
verbose_print "${pick_out}"
verbose_print "----------"
verbose_print "Auto-resolving ${AUTORESOLVE} using old version."
git show :2:${AUTORESOLVE} > ${AUTORESOLVE}
[[ $? != 0 ]] && git_recover
git add ${AUTORESOLVE}
[[ $? != 0 ]] && git_recover
# echo "Resolution of ${AUTORESOLVE} finished successfuly."
else
print_error "${pick_out}"
print_error "----------"
print_error "error: ${AUTORESOLVE} not found, cannot resolve"
git_recover
fi
# if $AUTORESOLVE was the only conflict, amend the commit
if [[ $(echo "${unmerged_files}" | wc -l) == 1 ]]; then
verbose_print "----------"
if [[ ${NO_AUTOCOMMIT} > 0 ]]; then
verbose_print "All done, autocommit disabled, nothing to do."
verbose_print "Please run git commit ${GIT_AMEND_OPTS} --amend" \
"after making all necessary changes."
verbose_print "Use ${GIT_RECOVER} to recover."
else
verbose_print "All done, running git commit ${GIT_AMEND_OPTS} --amend ..."
git_autoamend
fi
exit 0
# else let the user do all other conflict resolutions
else
print_error "${pick_out}"
echo "----------"
echo "Please run git commit ${GIT_AMEND_OPTS} --amend" \
"after resolving all conflicts."
echo "To recover from the resolution, use ${GIT_RECOVER}."
exit ${CONFLICT_RETVAL}
fi

View file

@ -1,38 +0,0 @@
#!/bin/sh
# Simple helper script to create backport lists
# By user defined (remote/branch to the to-be-backported history)
COMPARE_PATH="wotlk/master"
OUTPUT_FILE="contrib/backporting/todo_wotlk_commits.log"
# By user defined (text format)
#SMALL_FORMAT="wotlk: %h * %an (committer %cn)"
#FULL_FORMAT="${SMALL_FORMAT}: %s"
#FOOTER_FORMAT="FILE LAST UPDATED BASED ON... ${SMALL_FORMAT}"
# By user defined (Textile markup based wiki format)
SMALL_FORMAT="\"three\":http://github.com/mangosthree/server/commit/%h: %h * %an (committer %cn)"
FULL_FORMAT="</code></pre>%n* ${SMALL_FORMAT}<pre><code>%s"
FOOTER_FORMAT="</code></pre>FILE LAST UPDATED BASED ON... ${SMALL_FORMAT}"
# param1 must be the commit hash of last backported commit (of original commit)
if [ "$#" != "1" ]
then
echo "You must provide the last commit's hash of the \"$OUTPUT_FILE\" file"
exit 1
fi
# are we in git root dir?
if [[ ! -d .git/ ]]; then
echo "ERROR: This script is expected to be called from repository root directory"
echo "Try: contrib/backporting/update-commit-log.sh"
exit 1
fi
HASH=$1
git log $HASH..$COMPARE_PATH --pretty=format:"${FULL_FORMAT}" --reverse --dirstat >> $OUTPUT_FILE
echo "" >> $OUTPUT_FILE
echo "$(git log -1 --pretty="${FOOTER_FORMAT}" $COMPARE_PATH)" >> $OUTPUT_FILE
echo "" >> $OUTPUT_FILE

View file

@ -1 +0,0 @@
cleanupTools.config

View file

@ -1,133 +0,0 @@
#!/bin/sh
#
# Tool to rebase a branch with cleaned commits
#
# Required:
# - some tool for the cleanup
# - base commit from which on the current branch shall be cleaned
# Do config stuff
sh "${0%/*}/cleanupToolConfig.sh"
if [ "$?" != "0" ]
then
echo "You need to edit the configuration file before you can use this tool!"
echo "Configuration file: ${0%/*}/cleanupTools.config"
exit 0
fi
# And use config settings
. "${0%/*}/cleanupTools.config"
if [ "$BASE_COMMIT" = "" ]
then
echo "You did not specify a base-commit onto which to rebuild history"
echo "or another unexpected error happened.."
exit 1
fi
# First: commit all changes onto current branch
git commit -a -m"Cleanup History Commit: Pending Changes of WorkDir"
# Create list of commits that needs to be processed
COMMIT_LIST=`git log --reverse --format=format:"%H" $BASE_COMMIT..HEAD`
# prepare history_cleanup branch
git checkout -b history_cleanup $BASE_COMMIT
# cleanup history
echo "Cleanup History Tool: Cleanup initial state before rewriting history(might result in an empty commit)"
$CLEANUP_TOOL > /dev/null
git commit -a -m"Cleanup History Commit: Cleanup state before starting cleaning history"
for commit in $COMMIT_LIST
do
git checkout -b history_cleanup_tmp $commit
[[ $? != 0 ]] && exit 1
echo "Cleanup History Tool: Cleanup after commit $commit)"
$CLEANUP_TOOL > /dev/null
git commit -a -m"Cleanup History Commit: Temp cleaned" --allow-empty
[[ $? != 0 ]] && exit 1
git checkout history_cleanup
[[ $? != 0 ]] && exit 1
## Catch differences
git diff --binary history_cleanup..history_cleanup_tmp > history_cleanup_tmp.patch
# Get committer information to store it
COMMITTER_N=$(git show -s --pretty=format:'%cn' ${commit})
[[ $? != 0 ]] && exit 1
COMMITTER_M=$(git show -s --pretty=format:'%ce' ${commit})
[[ $? != 0 ]] && exit 1
COMMITTER_D=$(git show -s --pretty=format:'%cd' ${commit})
[[ $? != 0 ]] && exit 1
GIT_COMMITTER_NAME=$COMMITTER_N; GIT_COMMITTER_EMAIL=$COMMITTER_M; GIT_COMMITTER_DATE=$COMMITTER_D;
export GIT_COMMITTER_NAME; export GIT_COMMITTER_EMAIL; export GIT_COMMITTER_DATE;
# Two cases: either diff is identical to original commit, or not
git diff --binary $commit^..$commit > history_cleanup_compare.patch
DIFF_COUNT=`diff history_cleanup_tmp.patch history_cleanup_compare.patch | grep ">" | grep -v "> index " | wc -l`
echo "Current State: Diffcount=$DIFF_COUNT"
if [ "$DIFF_COUNT" = " 0" ]
then # identical# TODO this is too strict!
git cherry-pick $commit
else # different, use new commit
# commit object hash
COMMIT_HASH=$(git show -s --pretty=format:'%h' ${commit})
[[ $? != 0 ]] && exit 1
# subject
COMMIT_SUBJECT=$(git show -s --pretty=format:'%s' ${commit})
[[ $? != 0 ]] && exit 1
# body
COMMIT_BODY=$(git show -s --pretty=format:'%b' ${commit})
[[ $? != 0 ]] && exit 1
# whole message
COMMIT_MESSAGE=$(echo -e "${COMMIT_SUBJECT}\n\n${COMMIT_BODY}\n\n(cleaned version of ${COMMIT_HASH})")
[[ $? != 0 ]] && exit 1
# Apply Cleaned changeset
git apply history_cleanup_tmp.patch
if [ $? != 0 ]
then
echo "Could not apply patch with git methods, try with patch tool directly? (y/n)"
read line
if [ "$line" = "y" ]
then
patch -p1 -d. < history_cleanup_tmp.patch
echo "Please check manually if this worked.."
echo "Did it work? (y/n)"
read line
if [ "$line" != "y" ]
then
exit 1
fi
fi
fi
if [ $? != 0 ]
then
echo "Could not apply patch, store in history_cleanup_tmp.patch"
exit 1
fi
# Git add new files
NEW_FILES_LIST=`grep -B1 "new file mode" history_cleanup_tmp.patch | grep "diff --git a/" | sed 's!diff --git a/\(.*\) .*!\1!'`
for fline in $NEW_FILES_LIST
do
git add $fline
[[ $? != 0 ]] && exit 1
done
# Commit just created commit with original information
git commit -a --allow-empty -C"$commit"
[[ $? != 0 ]] && exit 1
git commit --amend --allow-empty -m"${COMMIT_MESSAGE}"
[[ $? != 0 ]] && exit 1
fi
git branch -D history_cleanup_tmp
[[ $? != 0 ]] && exit 1
done
rm history_cleanup_tmp.patch
rm history_cleanup_compare.patch
GIT_COMMITTER_NAME=""; GIT_COMMITTER_EMAIL=""; GIT_COMMITTER_DATE="";
export GIT_COMMITTER_NAME; export GIT_COMMITTER_EMAIL; export GIT_COMMITTER_DATE;

View file

@ -1,203 +0,0 @@
#!/bin/sh
# SUPPORTED: ASTYLE COMMENT_STYLE OVERRIDE_CORRECTNESS
# ASTYLE <- runs AStyle
# COMMENT_STYLE <- converts //bla to // bla (note, // Bla might be better, but this would conflict with code (at least)
# Use at own Risk:
# OVERRIDE_CORRECTNESS[2] <- Appends override correctness (add 2 for second pass)
# Do config stuff
sh "${0%/*}/cleanupToolConfig.sh"
if [ "$?" != "0" ]
then
echo "You need to edit the configuration file before you can use this tool!"
echo "Configuration file: ${0%/*}/cleanupTools.config"
exit 0
fi
# And use config settings
. "${0%/*}/cleanupTools.config"
## Internal Stuff
# Mangos Cleanup options for AStyle
OPTIONS="--convert-tabs --align-pointer=type --suffix=none \
--keep-one-line-blocks --keep-one-line-statements \
--indent-classes --indent-switches --indent-namespaces \
--pad-header --unpad-paren --pad-oper --style=allman"
if [ "$DO_ON" = "MANGOS_SRC" ]
then
FILEPATH=$BASEPATH/src
OPTIONS="$OPTIONS --exclude=ScriptDev2"
elif [ "$DO_ON" = "MANGOS_CONTRIB" ]
then
FILEPATH=$BASEPATH/contrib
elif [ "$DO_ON" = "MANGOS_WHOLE" ]
then
FILEPATH=$BASEPATH
OPTIONS="$OPTIONS --exclude=ScriptDev2"
elif [ "$DO_ON" = "SD2" ]
then
FILEPATH=$BASEPATH/src/bindings/ScriptDev2
else
exit 1
fi
OPTIONS="$OPTIONS --recursive"
####################################################################################################
## USING ASTYLE UPDATING ##
####################################################################################################
if [ $DO = ASTYLE ]
then
echo "Process $FILEPATH with options $MOPTIONS"
$ASTYLE $OPTIONS "$FILEPATH/*.cpp" "$FILEPATH/*.h"
#Restore style of auto-generated sql-files
if [ "$DO_ON" = "MANGOS_SRC" -o "$DO_ON" = "MANGOS_WHOLE" ]
then
if [ -f "$BASEPATH/src/shared/revision_nr.h" ]
then
sed 's/^#define REVISION_NR/ #define REVISION_NR/g' < ${BASEPATH}/src/shared/revision_nr.h > temp
mv temp "$BASEPATH/src/shared/revision_nr.h"
fi
if [ -f "$BASEPATH/src/shared/revision_sql.h" ]
then
sed 's/^#define REVISION_DB/ #define REVISION_DB/g' < ${BASEPATH}/src/shared/revision_sql.h > temp
mv temp "$BASEPATH/src/shared/revision_sql.h"
fi
elif [ "$DO_ON" = "SD2" ]
then
if [ -f "$BASEPATH/src/bindings/ScriptDev2/sd2_revision_nr.h" ]
then
sed 's/^#define SD2_REVISION_NR/ #define SD2_REVISION_NR/g' < ${BASEPATH}/src/bindings/ScriptDev2/sd2_revision_nr.h > temp
mv temp "$BASEPATH/src/bindings/ScriptDev2/sd2_revision_nr.h"
fi
fi
echo "Processing $DO on $DO_ON done"
exit 0
fi
####################################################################################################
## UNIFYING COMMENTS ##
####################################################################################################
## Make comments neater //bla => // bla ## note for uppercase s:\// \([a-z]\):// \1:g
if [ $DO = COMMENT_STYLE ]
then
if [ "$DO_ON" = "MANGOS_SRC" ]
then
LIST=`find ${BASEPATH}/src/ -path "${BASEPATH}/src/bindings/ScriptDev2" -prune -o -type f -iname "*.cpp" -print -o -iname "*.h" -print `
elif [ "$DO_ON" = "SD2" ]
then
LIST=`find ${BASEPATH}/src/bindings/ScriptDev2 -type f -iname "*.cpp" -o -iname "*.h" `
else
echo "Unsupported combination with DO and DO_ON"
exit 1
fi
for l in $LIST
do
echo "Converting comments in $l"
sed '/http:/ !s:\//\([a-zA-Z0-9]\):// \1:g;
s#^\(............................................................\) [ ]*//#\1//#g;
/^..............................................\/[\/]*$/ !s#^\(..................................................\)//#\1 //#g; ' "$l" > temp
if [ "$?" != "0" ]
then
echo "An error HAPPENED"
exit 1
fi
mv temp "$l"
done
echo "Processing $DO on $DO_ON done"
exit 0
fi
####################################################################################################
## OVERRIDE CORRECTNESS ##
####################################################################################################
# use OVERRIDE_CORRECTNESS to create helper file listing all virtual methods
# use OVERRIDE_CORRECTNESS2 to add the word "override" after all functions with virtual names
if [ "$DO_ON" != "MANGOS_SRC" -a "$DO_ON" != "SD2" ]
then
echo "OVERRIDE atm only supported for MANGOS_SRC or SD2 target"
exit 0
fi
if [ $DO = OVERRIDE_CORRECTNESS ]
then
#Create a list of all virtual functions in mangos (class scope)
if [ $DO_ON = MANGOS_SRC ]
then
HEADERLIST=`find ${BASEPATH}/src/ -path "${BASEPATH}/src/bindings/ScriptDev2" -prune -o -type f -iname "*.h" -print`
else
HEADERLIST=`find ${BASEPATH}/src/bindings/ScriptDev2 -type f -iname "*.h"`
HEADERLIST="${HEADERLIST} ${BASEPATH}/src/game/CreatureAI.h"
HEADERLIST="${HEADERLIST} ${BASEPATH}/src/game/InstanceData.h"
fi
rm virtuals
for h in $HEADERLIST
do
grep "virtual" "$h" >> virtuals
done
#Filter comment lines
sed -n '/^[ ]*\/\// !p' virtuals | sed -n '/^[ ]*\/\*/ !p' | \
##Get function name
sed -r -n '/^[ ]*virtual[ ][ ]*const[\*]*[ ][ ]*[a-zA-Z_~0-9\*:&]*[ ][ ]*const[\*]*[ ][]*[a-zA-Z_~0-9]*[ ]*\(.*\)/ { s/^[ ]*virtual[ ]*const[ ]*[a-zA-Z_~0-9\*:]*[ ]*const[ ]*([a-zA-Z_~0-9]*).*/\1/g; tEnde}
/^[ ]*virtual[ ][ ]*const[\*]*[ ][ ]*[a-zA-Z_~0-9\*:&]*[ ][ ]*[a-zA-Z_~0-9]*[ ]*\(.*\)/ { s/^[ ]*virtual[ ]*const[ ]*[a-zA-Z_~0-9\*:]*[ ]*([a-zA-Z_~0-9]*).*/\1/g; tEnde}
/^[ ]*virtual[ ][ ]*[a-zA-Z_~0-9\*:&]*[ ][ ]*const[\*]*[ ][ ]*[a-zA-Z_~0-9]*[ ]*\(.*\)/ { s/^[ ]*virtual[ ]*[a-zA-Z_~0-9\*:]*[ ]*const[\*]*[ ]*([a-zA-Z_~0-9]*).*/\1/g; tEnde}
/^[ ]*virtual[ ]*[a-zA-Z_~0-9\*:&]*[ ][ ]*[a-zA-Z_~0-9]*[ ]*\(.*\)/ { s/^[ ]*virtual[ ]*[a-zA-Z_~0-9\*:]*[ ][ ]*([a-zA-Z_~0-9]*).*/\1/g;}
:Ende; p' > virtualNames
##Make its entries unique
sort < virtualNames > virtuals
uniq < virtuals > virtualNames
echo "Check file virtualNames for inconsitencies!"
rm virtuals
echo "Processing $DO on $DO_ON done"
exit 0
fi
if [ $DO = OVERRIDE_CORRECTNESS2 ]
then
## Assume virtualNames is good
if [ $DO_ON = MANGOS_SRC ]
then
FILELIST=`find ${BASEPATH}/src/ -path "${BASEPATH}/src/bindings/ScriptDev2" -prune -o -type f -iname "*.h" -print`
else
FILELIST=`find ${BASEPATH}/src/bindings/ScriptDev2 -type f -iname "*.cpp" -o -iname "*.h"`
fi
for h in $FILELIST
do
echo "Progress file $h"
while read f
do
# basic pattern: NAME(..)...[;]
PARSE="s/( "$f"\(.*\)[ ]*const[\*]*);/\1 override;/g; t
s/( "$f"\(.*\));/\1 override;/g; t
s/( "$f"\(.*\)[ ]*const[\*]*)$/\1 override/g; t
s/( "$f"\(.*\))$/\1 override/g; t
s/( "$f"\(.*\)[ ]*const[\*]*)([ ].*)/\1 override\2/g; t
s/( "$f"\(.*\))([ ].*)/\1 override\2/g"
sed -r "$PARSE" "$h" > temp
mv temp "$h"
done < virtualNames
done
echo "Processing $DO on $DO_ON done"
exit 0
fi
exit 0

View file

@ -1,68 +0,0 @@
#!/bin/sh
# Helper script to create a config file for the cleanup tools
# The created config file must be edited manually
if [ -f "${0%/*}/cleanupTools.config" ]
then
# file already exists, exit
exit 0
fi
# Create file
cat << EOF > "${0%/*}/cleanupTools.config"
#!/bin/sh
# Basic configuration for the cleanup helper scripts with mangos
# Be sure to read this whole file and edit the variables as required
#
############################################################
# Generic options:
############################################################
# Define the path to <MaNGOS> folder relatively from where you want to call the scripts.
# The cleanupHistory.sh script must be called from within the repository that is to be cleaned!
#
BASEPATH="."
#
# Path to Astyle from the <MaNGOS> directory
ASTYLE="../AStyle/bin/AStyle.exe"
############################################################
# The cleanupStyle.sh tool:
############################################################
# Job selection options are:
# DO with possible choices: ASTYLE (to call the Astyle tool)
# COMMENT_STYLE (to change comments from //foo to // foo and align them to column 61 if possible
# OVERRIDE_CORRECTNESS[2] use at own RISK, this is maybe not too usefull
DO="ASTYLE"
#
# DO_ON with possible choices: MANGOS_SRC to invoke the above cleanup routine on <MaNGOS>/src directory and subdirectories
# MANGOS_CONTRIB to invoke the above cleanup routine on <MaNGOS>/contrib directory and subdirectories
# MANGOS_WHOLE to invoke the above cleanup routine on <MaNGOS> directory and subdirectories
# SD2 to invoke the above cleanup routine on <MaNGOS>/src/bindings/ScriptDev2 directory and subdirectories
DO_ON="MANGOS_SRC"
############################################################
# The cleanupHistory.sh tool:
############################################################
# This tool will USE the cleanupStyle.sh tool to cleanup the history of the current branch with the settings above
# It will clean the history based on the variable BASE_COMMIT that needs to be defined here
BASE_COMMIT=""
###
# Internal variables, do not change except you know what you are doing
###
# cleanup-tool
CLEANUP_TOOL="\$BASEPATH/contrib/cleanupTools/cleanupStyle.sh"
# path from current's caller position to ASTYLE
ASTYLE="\$BASEPATH/\$ASTYLE"
EOF
# Return wil error, to display message if file is not found
exit 1

View file

@ -1,34 +0,0 @@
[TaxiNodes.dbc]
ColType2=0
ColType3=1
ColType4=1
[SpellRange.dbc]
ColType2=0
ColType3=0
ColType1=0
[Talent.dbc]
ColType1=0
ColType5=0
ColType4=0
[test.dbc]
ColType1=0
ColType3=1
ColType2=0
[TalentTab.dbc]
ColType15=2
[TalentTab_new.dbc]
ColType15=2
[SpellIcon.dbc]
ColType2=0
ColType1=0
[FactionGroup.dbc]
ColType12=0
ColType3=2
ColType2=0
ColType8=0
[gtRegenMPPerSpt.dbc]
ColType1=1
[gtOCTRegenMP.dbc]
ColType1=1
[gtOCTRegenHP.dbc]
ColType1=1

View file

@ -1,26 +0,0 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "SearchFrm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrmSearch* FrmSearch;
//---------------------------------------------------------------------------
__fastcall TFrmSearch::TFrmSearch(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFrmSearch::btOkClick(TObject* Sender)
{
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TFrmSearch::btCancelClick(TObject* Sender)
{
ModalResult = mrCancel;
}
//---------------------------------------------------------------------------

Binary file not shown.

View file

@ -1,63 +0,0 @@
object FrmSearch: TFrmSearch
Left = 261
Top = 194
Width = 324
Height = 215
Caption = 'Seach F3 Seach Next'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object lbseach: TLabel
Left = 48
Top = 16
Width = 57
Height = 17
AutoSize = False
Caption = 'Input:'
end
object rgSI: TRadioGroup
Left = 64
Top = 40
Width = 185
Height = 97
Caption = 'Seach Dir'
ItemIndex = 1
Items.Strings = (
'Seach up'
'Seach down'
'Seach up Current rol'
'Seach down Current rol')
TabOrder = 0
end
object edSeach: TEdit
Left = 120
Top = 16
Width = 121
Height = 21
TabOrder = 1
end
object btOk: TButton
Left = 64
Top = 152
Width = 75
Height = 25
Caption = 'Ok'
TabOrder = 2
OnClick = btOkClick
end
object btCancel: TButton
Left = 176
Top = 152
Width = 75
Height = 25
Caption = 'Cancel'
TabOrder = 3
OnClick = btCancelClick
end
end

View file

@ -1,29 +0,0 @@
//---------------------------------------------------------------------------
#ifndef SearchFrmH
#define SearchFrmH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TFrmSearch : public TForm
{
__published: // IDE-managed Components
TRadioGroup* rgSI;
TEdit* edSeach;
TLabel* lbseach;
TButton* btOk;
TButton* btCancel;
void __fastcall btOkClick(TObject* Sender);
void __fastcall btCancelClick(TObject* Sender);
private: // User declarations
public: // User declarations
__fastcall TFrmSearch(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFrmSearch* FrmSearch;
//---------------------------------------------------------------------------
#endif

View file

@ -1,26 +0,0 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "TitleFrm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrmTitle* FrmTitle;
//---------------------------------------------------------------------------
__fastcall TFrmTitle::TFrmTitle(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFrmTitle::Button1Click(TObject* Sender)
{
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TFrmTitle::Button2Click(TObject* Sender)
{
ModalResult = mrCancel;
}
//---------------------------------------------------------------------------

Binary file not shown.

View file

@ -1,51 +0,0 @@
object FrmTitle: TFrmTitle
Left = 328
Top = 252
Width = 235
Height = 112
BorderIcons = [biSystemMenu]
Caption = 'Col Title'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 8
Top = 24
Width = 65
Height = 13
AutoSize = False
Caption = 'Title:'
end
object edTitle: TEdit
Left = 80
Top = 16
Width = 121
Height = 21
TabOrder = 0
end
object Button1: TButton
Left = 24
Top = 48
Width = 75
Height = 25
Caption = 'Ok'
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 136
Top = 48
Width = 75
Height = 25
Caption = 'Cancel'
TabOrder = 2
OnClick = Button2Click
end
end

View file

@ -1,27 +0,0 @@
//---------------------------------------------------------------------------
#ifndef TitleFrmH
#define TitleFrmH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TFrmTitle : public TForm
{
__published: // IDE-managed Components
TLabel* Label1;
TEdit* edTitle;
TButton* Button1;
TButton* Button2;
void __fastcall Button1Click(TObject* Sender);
void __fastcall Button2Click(TObject* Sender);
private: // User declarations
public: // User declarations
__fastcall TFrmTitle(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFrmTitle* FrmTitle;
//---------------------------------------------------------------------------
#endif

View file

@ -1,826 +0,0 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "dbcedit.h"
#include "stdio.h"
#include "IdGlobal.hpp"
#include <inifiles.hpp>
#include "TitleFrm.h"
#include <dir.h>
#include "thOpenSource.h"
#include "SearchFrm.h"
//#include "SysUtils.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrmMain* FrmMain;
//---------------------------------------------------------------------------
__fastcall TFrmMain::TFrmMain(TComponent* Owner)
: TForm(Owner)
{
OpenOk = false;
Term = false;
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::btOpenClick(TObject* Sender)
{
if (OpenDialog1->Execute())
{
if (FileExists(OpenDialog1->FileName))
{
OpenOk = false;
if (thOpen)
{
thOpen->Terminate();
}
thOpen = new thOpenFile(false);
//thOpen->Priority = tpTimeCritical;
pnFileName->Caption = OpenDialog1->FileName;
}
else
{
OpenOk = false;
pnFileName->Caption = "";
}
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::btSaveClick(TObject* Sender)
{
//CurrentOpenFile;
if (OpenOk)
{
SaveToFile(CurrentOpenFile.c_str());
}
else
{
ShowMessage("文件未打开完成!");
}
}
//---------------------------------------------------------------------------
void TFrmMain::SaveToFile(const char* pszFileName)
{
char szFileName[255];
FILE* stream;
fnsplit(pszFileName, 0, 0, szFileName, 0);
strcat(szFileName, "_new.dbc");
AnsiString NewFileName = ExtractFilePath(Application->ExeName) + szFileName; //=pszFileName;
int iFileHandle; //文件句柄
AnsiString iniSetFile = ExtractFilePath(Application->ExeName) + "BcdEditer.ini";
AnsiString SectionName = ExtractFileName(CurrentOpenFile);
DWORD w;
CopyFileTo(pszFileName, NewFileName);
iFileHandle = FileOpen(NewFileName, fmOpenRead | fmOpenWrite); //打开文件
if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
== NULL)
{
ShowMessage("打开文件出错");
return;
}
int iVal;
float fVal;
bool isFloat;
int ColType;
FileSeek(iFileHandle, 0x14, 0);
TIniFile* ini;
ini = new TIniFile(iniSetFile);
for (int i = 1; i < sgEdit->RowCount; i++)
{
for (int j = 1; j < sgEdit->ColCount; j++)
{
if (j == 1) //ID
{
iVal = StrToInt(sgEdit->Cells[j][i]);
FileWrite(iFileHandle, &iVal, 4);
}
else
{
//ColType= ini->ReadInteger(SectionName,"ColType"+IntToStr(j-1),0);
//thOpen->ColType[10000];
switch (thOpen->ColType[j])
{
case 0: //整型
iVal = StrToFloat(sgEdit->Cells[j][i]);
FileWrite(iFileHandle, &iVal, 4);
break;
case 1: //浮点
fVal = StrToFloat(sgEdit->Cells[j][i]);
FileWrite(iFileHandle, &fVal, 4);
break;
case 2: //文本
fseek(stream, 0x14 + (i * (sgEdit->ColCount - 1) + (j - 1)) * 4, 0);
fread(&iVal, 4, 1, stream);
FileWrite(iFileHandle, &iVal, 4);
break;
default: //整型
iVal = StrToFloat(sgEdit->Cells[j][i]);
FileWrite(iFileHandle, &iVal, 4);
}
}
}
}
FileClose(iFileHandle);
fclose(stream);
delete ini;
ShowMessage("Save To File:" + NewFileName);
}
void __fastcall TFrmMain::btIntTypeClick(TObject* Sender)
{
if (OpenOk == true)
{
AnsiString iniSetFile = ExtractFilePath(Application->ExeName) + "BcdEditer.ini";
AnsiString SectionName = ExtractFileName(CurrentOpenFile);
TIniFile* ini;
ini = new TIniFile(iniSetFile);
ini->WriteInteger(SectionName, "ColType" + IntToStr(sgEdit->Col), 0);
delete ini;
thOpen->ColType[sgEdit->Col] = 0;
//重新打开对应列的值
//OpenFileCol(AnsiString FileName,int ColType);
OpenFileCol(CurrentOpenFile, sgEdit->Col, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::btFloatTypeClick(TObject* Sender)
{
if (OpenOk == true)
{
AnsiString iniSetFile = ExtractFilePath(Application->ExeName) + "BcdEditer.ini";
AnsiString SectionName = ExtractFileName(CurrentOpenFile);
TIniFile* ini;
ini = new TIniFile(iniSetFile);
ini->WriteInteger(SectionName, "ColType" + IntToStr(sgEdit->Col), 1);
delete ini;
thOpen->ColType[sgEdit->Col] = 1;
OpenFileCol(CurrentOpenFile, sgEdit->Col, 1);
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::PopupMenu1Popup(TObject* Sender)
{
if (OpenOk == true)
{
AnsiString iniSetFile = ExtractFilePath(Application->ExeName) + "BcdEditer.ini";
AnsiString SectionName = ExtractFileName(CurrentOpenFile);
int ColType;
TIniFile* ini;
ini = new TIniFile(iniSetFile);
ColType = ini->ReadInteger(SectionName, "ColType" + IntToStr(sgEdit->Col), 0);
delete ini;
switch (ColType)
{
case 0:
btIntType->Checked = true;
btFloatType->Checked = false;
btTxtType->Checked = false;
break;
case 1:
btIntType->Checked = false;
btFloatType->Checked = true;
btTxtType->Checked = false;
break;
case 2:
btIntType->Checked = false;
btFloatType->Checked = false;
btTxtType->Checked = true;
break;
default:
btIntType->Checked = true;
btFloatType->Checked = false;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::N1Click(TObject* Sender)
{
AnsiString iniSetFile = ExtractFilePath(Application->ExeName) + "BcdEditer.ini";
AnsiString SectionName = ExtractFileName(CurrentOpenFile);
int ColType;
FrmTitle->edTitle->Text = sgEdit->Cells[sgEdit->Col][0];
if (FrmTitle->ShowModal() == mrOk)
{
TIniFile* ini;
ini = new TIniFile(iniSetFile);
ini->WriteString(SectionName, "ColTitle" + IntToStr(sgEdit->Col), FrmTitle->edTitle->Text);
delete ini;
sgEdit->Cells[sgEdit->Col][0] = FrmTitle->edTitle->Text;
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::FormDestroy(TObject* Sender)
{
if (thOpen)
{
thOpen->Terminate();
SleepEx(200, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::ToolButton1Click(TObject* Sender)
{
bool SeFlag = true;
if (FrmSearch->ShowModal() == mrOk)
{
switch (FrmSearch->rgSI->ItemIndex)
{
case 0: //向上找;
for (int i = sgEdit->ColCount * sgEdit->Row + sgEdit->Col - 1; i > sgEdit->ColCount; i--)
{
if (i % sgEdit->ColCount != 0)
{
if (0 == CompareStr(sgEdit->Cells[i - sgEdit->ColCount * (i / sgEdit->ColCount)][i / sgEdit->ColCount],
FrmSearch->edSeach->Text)) //找到了
{
sgEdit->Col = i - sgEdit->ColCount * i / sgEdit->ColCount;
sgEdit->Row = i / sgEdit->ColCount;
SeFlag = false;
break;
}
}
}
if (SeFlag) ShowMessage("Seach TopFind Nothing.");
break;
case 1: //向下找;
for (int i = sgEdit->ColCount * sgEdit->Row + sgEdit->Col + 1; i < sgEdit->ColCount * sgEdit->RowCount; i++)
{
if (i % sgEdit->ColCount != 0)
{
if (0 == CompareStr(sgEdit->Cells[i - sgEdit->ColCount * (i / sgEdit->ColCount)][i / sgEdit->ColCount],
FrmSearch->edSeach->Text)) //找到了
{
sgEdit->Col = i - sgEdit->ColCount * (i / sgEdit->ColCount);
sgEdit->Row = i / sgEdit->ColCount;
SeFlag = false;
break;
}
}
}
if (SeFlag) ShowMessage("Seach EndFind Nothing");
break;
case 2: //当前列向上找;
for (int i = sgEdit->Row; i > 1; i--)
{
if (0 == CompareStr(sgEdit->Cells[sgEdit->Col][i],
FrmSearch->edSeach->Text)) //找到了
{
sgEdit->Row = i;
SeFlag = false;
break;
}
}
if (SeFlag) ShowMessage("Seach col topFind Nothing");
break;
case 3: //当前列向下找;
for (int i = sgEdit->Row; i < sgEdit->RowCount; i++)
{
if (0 == CompareStr(sgEdit->Cells[sgEdit->Col][i],
FrmSearch->edSeach->Text)) //找到了
{
sgEdit->Row = i;
SeFlag = false;
break;
}
}
if (SeFlag) ShowMessage("Seach col endFind Nothing.");
break;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::sgEditKeyDown(TObject* Sender, WORD& Key,
TShiftState Shift)
{
bool SeFlag = true;
if (Key == VK_F3)
{
switch (FrmSearch->rgSI->ItemIndex)
{
case 0: //向上找;
for (int i = sgEdit->ColCount * sgEdit->Row + sgEdit->Col - 1; i > sgEdit->ColCount; i--)
{
if (i % sgEdit->ColCount != 0)
{
if (0 == CompareStr(sgEdit->Cells[i - sgEdit->ColCount * (i / sgEdit->ColCount)][i / sgEdit->ColCount],
FrmSearch->edSeach->Text)) //找到了
{
sgEdit->Col = i - sgEdit->ColCount * i / sgEdit->ColCount;
sgEdit->Row = i / sgEdit->ColCount;
SeFlag = false;
break;
}
}
}
if (SeFlag) ShowMessage("Seach TopFind Nothing.");
break;
case 1: //向下找;
for (int i = sgEdit->ColCount * sgEdit->Row + sgEdit->Col + 1; i < sgEdit->ColCount * sgEdit->RowCount; i++)
{
if (i % sgEdit->ColCount != 0)
{
if (0 == CompareStr(sgEdit->Cells[i - sgEdit->ColCount * (i / sgEdit->ColCount)][i / sgEdit->ColCount],
FrmSearch->edSeach->Text)) //找到了
{
sgEdit->Col = i - sgEdit->ColCount * (i / sgEdit->ColCount);
sgEdit->Row = i / sgEdit->ColCount;
SeFlag = false;
break;
}
}
}
if (SeFlag) ShowMessage("Seach EndFind Nothing.");
break;
case 2: //当前列向上找;
for (int i = sgEdit->Row; i > 1; i--)
{
if (0 == CompareStr(sgEdit->Cells[sgEdit->Col][i],
FrmSearch->edSeach->Text)) //找到了
{
sgEdit->Row = i;
SeFlag = false;
break;
}
}
if (SeFlag) ShowMessage("Seach col TopFind Nothing.");
break;
case 3: //当前列向下找;
for (int i = sgEdit->Row; i < sgEdit->RowCount; i++)
{
if (0 == CompareStr(sgEdit->Cells[sgEdit->Col][i],
FrmSearch->edSeach->Text)) //找到了
{
sgEdit->Row = i;
SeFlag = false;
break;
}
}
if (SeFlag) ShowMessage("Seach col endFind Nothing.");
break;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::sgEditSelectCell(TObject* Sender, int ACol,
int ARow, bool& CanSelect)
{
//
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::OpenFileCol(AnsiString FileName, int ColIndex, int ColType)
{
int iFileHandle; //文件句柄
char Txtbuf[255];
int iVal;
float fVal;
FILE* stream;
long curpos, length;
DWORD dwRows, dwCols, dwRowLen, dwTextLen;
DWORD dwTextStartPos;
char* pTextPtr ;
if ((stream = fopen(FileName.c_str(), "r+"))
== NULL)
{
ShowMessage("Open File Error");
return;
}
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
switch (ColType)
{
case 0: //整型值 Int
for (int i = 0; i < sgEdit->RowCount - 1; i++)
{
fseek(stream, 0x14 + (i * (sgEdit->ColCount - 1) + (ColIndex - 1)) * 4, 0);
fread(&iVal, 4, 1, stream);
sgEdit->Cells[ColIndex][i + 1] = IntToStr(iVal);
}
break;
case 1: //浮点值 Float
for (int i = 0; i < sgEdit->RowCount - 1; i++)
{
fseek(stream, 0x14 + (i * (sgEdit->ColCount - 1) + (ColIndex - 1)) * 4, 0);
fread(&fVal, 4, 1, stream);
sgEdit->Cells[ColIndex][i + 1] = FloatToStr(fVal);
}
break;
case 2: //文本 Text
fseek(stream, 0x4, 0);
fread(&iVal, 4, 1, stream);
dwRows = iVal;
fread(&iVal, 4, 1, stream);
dwCols = iVal;
fread(&iVal, 4, 1, stream);
dwRowLen = iVal;
fread(&iVal, 4, 1, stream);
dwTextLen = iVal;
dwTextStartPos = dwRows * dwRowLen + 20;
for (int i = 0; i < sgEdit->RowCount - 1; i++)
{
fseek(stream, 0x14 + (i * (sgEdit->ColCount - 1) + (ColIndex - 1)) * 4, 0);
fread(&iVal, 4, 1, stream);
sgEdit->Cells[ColIndex][i + 1] = IntToStr(iVal);
if (dwTextStartPos + iVal < length)
{
fseek(stream, dwTextStartPos + iVal, 0);
fread(Txtbuf, 1, 255, stream);
//pTextPtr = pBuff + dwTextStartPos + lTemp;
sgEdit->Cells[ColIndex][i + 1] = Txtbuf;
}
else
{
sgEdit->Cells[ColIndex][i + 1] = "This Col Not Text!";
}
}
break;
}
fclose(stream);
}
void __fastcall TFrmMain::Timer1Timer(TObject* Sender)
{
if (OpenOk)
{
lbOpState->Caption = "Open File Ok.";
}
else
{
lbOpState->Caption = "Open Now.....";
}
}
//---------------------------------------------------------------------------
//当前格子写入修改文件中
void __fastcall TFrmMain::N4Click(TObject* Sender)
{
if (!thOpen) return;
int iFileHandle; //文件句柄
char buf[4];
int iVal;
float fVal;
FILE* stream;
/*
if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
== NULL)
{
ShowMessage("打开文件出错");
return;
}
*/
iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead | fmOpenWrite); //打开文件
switch (thOpen->ColType[sgEdit->Col])
{
case 0: //整型值
//for(int i=0;i<sgEdit->RowCount-1;i++){
/*
fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0);
iVal=StrToInt(sgEdit->Cells[sgEdit->Col][sgEdit->Row]);
memcpy(buf, &iVal, 4);
for(int i=0;i<4;i++)
fwrite(buf+i, 1, 1, stream);
*/
iVal = StrToInt(sgEdit->Cells[sgEdit->Col][sgEdit->Row]);
memcpy(buf, &iVal, 4);
FileSeek(iFileHandle, 0x14 + ((sgEdit->Row - 1) * (sgEdit->ColCount - 1) + (sgEdit->Col - 1)) * 4, 0);
FileWrite(iFileHandle, buf, 4);
//}
break;
case 1: //浮点值
//fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0);
//fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][sgEdit->Row]);
//fwrite(&fVal, 4, 1, stream);
fVal = StrToFloat(sgEdit->Cells[sgEdit->Col][sgEdit->Row]);
memcpy(buf, &fVal, 4);
FileSeek(iFileHandle, 0x14 + ((sgEdit->Row - 1) * (sgEdit->ColCount - 1) + (sgEdit->Col - 1)) * 4, 0);
FileWrite(iFileHandle, buf, 4);
break;
case 2: //文本不写入
break;
}
// fclose(stream);
FileClose(iFileHandle);
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::btTxtTypeClick(TObject* Sender)
{
if (OpenOk == true)
{
AnsiString iniSetFile = ExtractFilePath(Application->ExeName) + "BcdEditer.ini";
AnsiString SectionName = ExtractFileName(CurrentOpenFile);
TIniFile* ini;
ini = new TIniFile(iniSetFile);
ini->WriteInteger(SectionName, "ColType" + IntToStr(sgEdit->Col), 2);
delete ini;
thOpen->ColType[sgEdit->Col] = 2;
OpenFileCol(CurrentOpenFile, sgEdit->Col, 2);
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::ToolButton3Click(TObject* Sender)
{
int OldCol;
int OldRow;
OldRow = sgEdit->Row;
OldCol = sgEdit->Col;
if (sgEdit->FixedCols == 1)
{
sgEdit->FixedCols = 2;
if (OldCol != 1)
sgEdit->Col = OldCol;
sgEdit->Row = OldRow;
}
else
{
sgEdit->FixedCols = 1;
sgEdit->Row = OldRow;
if (OldCol != 2)
sgEdit->Col = OldCol;
}
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::btRowSaveClick(TObject* Sender)
{
if (OpenOk == false) return;
int iFileHandle; //文件句柄
char Txtbuf[255];
int iVal;
char buf[4];
float fVal;
FILE* stream;
long curpos, length;
DWORD dwRows, dwCols, dwRowLen, dwTextLen;
DWORD dwTextStartPos;
char* pTextPtr ;
//if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
// == NULL)
//{
// ShowMessage("打开文件出错");
// return;
//}
//curpos = ftell(stream);
//fseek(stream, 0L, SEEK_END);
//length = ftell(stream);
iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead | fmOpenWrite); //打开文件
for (int i = 0; i < sgEdit->ColCount - 1; i++)
{
switch (thOpen->ColType[i])
{
case 0: //整型值 sgEdit->Row
//fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4, 0);
//iVal=StrToInt(sgEdit->Cells[i+1][sgEdit->Row]);
//fwrite(&iVal, 4, 1, stream);
iVal = StrToInt(sgEdit->Cells[i + 1][sgEdit->Row]);
memcpy(buf, &iVal, 4);
FileSeek(iFileHandle, 0x14 + ((sgEdit->Row - 1) * (sgEdit->ColCount - 1) + i) * 4, 0);
FileWrite(iFileHandle, buf, 4);
break;
case 1: //浮点值
//fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4, 0);
//fVal=StrToFloat(sgEdit->Cells[i+1][sgEdit->Row]);
//fwrite(&fVal, 4, 1, stream);
fVal = StrToFloat(sgEdit->Cells[i + 1][sgEdit->Row]);
memcpy(buf, &fVal, 4);
FileSeek(iFileHandle, 0x14 + ((sgEdit->Row - 1) * (sgEdit->ColCount - 1) + i) * 4, 0);
FileWrite(iFileHandle, buf, 4);
break;
case 2: //文本 不存
break;
}
}
//fclose(stream);
FileClose(iFileHandle);
ShowMessage("The " + IntToStr(sgEdit->Row) + " Row Write Ok!");
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::btColSaveClick(TObject* Sender)
{
if (OpenOk == false) return;
int iFileHandle; //文件句柄
char Txtbuf[255];
int iVal;
char buf[4];
float fVal;
FILE* stream;
long curpos, length;
DWORD dwRows, dwCols, dwRowLen, dwTextLen;
DWORD dwTextStartPos;
char* pTextPtr ;
iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead | fmOpenWrite); //打开文件
//if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
// == NULL)
//{
// ShowMessage("打开文件出错");
// return;
//}
//curpos = ftell(stream);
//fseek(stream, 0L, SEEK_END);
//length = ftell(stream);
switch (thOpen->ColType[sgEdit->Col])
{
case 0: //整型值
for (int i = 0; i < sgEdit->RowCount - 1; i++)
{
//fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0);
//iVal=StrToInt(sgEdit->Cells[sgEdit->Col][i+1]);
//fwrite(&iVal, 4, 1, stream);
iVal = StrToInt(sgEdit->Cells[sgEdit->Col][i + 1]);
memcpy(buf, &iVal, 4);
FileSeek(iFileHandle, 0x14 + (i * (sgEdit->ColCount - 1) + (sgEdit->Col - 1)) * 4, 0);
FileWrite(iFileHandle, buf, 4);
}
break;
case 1: //浮点值
for (int i = 0; i < sgEdit->RowCount - 1; i++)
{
//fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0);
//fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][i+1]);
//fwrite(&fVal, 4, 1, stream);
fVal = StrToFloat(sgEdit->Cells[sgEdit->Col][i + 1]);
memcpy(buf, &fVal, 4);
FileSeek(iFileHandle, 0x14 + (i * (sgEdit->ColCount - 1) + (sgEdit->Col - 1)) * 4, 0);
FileWrite(iFileHandle, buf, 4);
}
break;
case 2: //文本 不存
break;
}
//fclose(stream);
FileClose(iFileHandle);
ShowMessage("The " + IntToStr(sgEdit->Col) + "Col Write Ok!");
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::btRowClearClick(TObject* Sender)
{
if (OpenOk == false) return;
int iFileHandle; //文件句柄
char Txtbuf[255];
int iVal;
float fVal;
FILE* stream;
long curpos, length;
DWORD dwRows, dwCols, dwRowLen, dwTextLen;
DWORD dwTextStartPos;
char* pTextPtr ;
if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
== NULL)
{
ShowMessage("Open File Error!");
return;
}
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
for (int i = 1; i < sgEdit->ColCount - 1; i++)
{
switch (thOpen->ColType[i])
{
case 0: //整型值 sgEdit->Row
//fseek(stream, 0x14+(sgEdit->Row*(sgEdit->ColCount-1)+i)*4, 0);
//iVal=StrToInt(sgEdit->Cells[i+1][sgEdit->Row]);
//fwrite(&iVal, 4, 1, stream);
sgEdit->Cells[i + 1][sgEdit->Row] = "0";
break;
case 1: //浮点值
//fseek(stream, 0x14+(sgEdit->Row*(sgEdit->ColCount-1)+i)*4, 0);
//fVal=StrToFloat(sgEdit->Cells[i+1][sgEdit->Row]);
//fwrite(&fVal, 4, 1, stream);
sgEdit->Cells[i + 1][sgEdit->Row] = "0";
break;
case 2: //文本 不存
break;
}
}
fclose(stream);
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::btColClearClick(TObject* Sender)
{
if (OpenOk == false) return;
int iFileHandle; //文件句柄
char Txtbuf[255];
int iVal;
float fVal;
FILE* stream;
long curpos, length;
DWORD dwRows, dwCols, dwRowLen, dwTextLen;
DWORD dwTextStartPos;
char* pTextPtr ;
if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
== NULL)
{
ShowMessage("Open File Error!");
return;
}
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
switch (thOpen->ColType[sgEdit->Col])
{
case 0: //整型值
for (int i = 0; i < sgEdit->RowCount - 1; i++)
{
//fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0);
//iVal=StrToInt(sgEdit->Cells[ColIndex][i+1]);
//fwrite(&iVal, 4, 1, stream);
sgEdit->Cells[sgEdit->Col][i + 1] = "0";
}
break;
case 1: //浮点值
for (int i = 0; i < sgEdit->RowCount - 1; i++)
{
//fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0);
//fVal=StrToFloat(sgEdit->Cells[ColIndex][i+1]);
//fwrite(&fVal, 4, 1, stream);
sgEdit->Cells[sgEdit->Col][i + 1] = "0";
}
break;
case 2: //文本 不存
break;
}
fclose(stream);
}
//---------------------------------------------------------------------------
void __fastcall TFrmMain::ToolButton4Click(TObject* Sender)
{
AnsiString Cmd;
Cmd = "calc.exe";
WinExec(Cmd.c_str(), SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -1,105 +0,0 @@
//---------------------------------------------------------------------------
#ifndef dbceditH
#define dbceditH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <ToolWin.hpp>
#include <Grids.hpp>
#include <Dialogs.hpp>
#include <Menus.hpp>
#include <ImgList.hpp>
#include "thOpenSource.h"
union TypePtr
{
long* l;
DWORD* dw;
WORD* w;
char* c;
void* p;
float* f;
TypePtr(void* in) : p(in)
{
}
};
#define TAG(x) (DWORD)( (((DWORD)x&0x0000ff00)<<8)+(((DWORD)x&0x000000ff)<<24)+(((DWORD)x&0x00ff0000)>>8)+(((DWORD)x&0xff000000)>>24) )
//---------------------------------------------------------------------------
class TFrmMain : public TForm
{
__published: // IDE-managed Components
TPanel* Panel1;
TCoolBar* CoolBar1;
TToolBar* ToolBar1;
TToolButton* btOpen;
TToolButton* btSave;
TStringGrid* sgEdit;
TOpenDialog* OpenDialog1;
TPopupMenu* PopupMenu1;
TMenuItem* N1;
TMenuItem* N2;
TMenuItem* btIntType;
TMenuItem* btFloatType;
TMenuItem* btTxtType;
TImageList* ImageList1;
TPanel* pnFileName;
TToolButton* ToolButton1;
TToolButton* ToolButton2;
TTimer* Timer1;
TLabel* lbOpState;
TMenuItem* N4;
TToolButton* ToolButton3;
TMenuItem* btRowSave;
TMenuItem* btColSave;
TMenuItem* btRowClear;
TMenuItem* btColClear;
TToolButton* ToolButton4;
TToolButton* ToolButton5;
void __fastcall btOpenClick(TObject* Sender);
void __fastcall btSaveClick(TObject* Sender);
void __fastcall btIntTypeClick(TObject* Sender);
void __fastcall btFloatTypeClick(TObject* Sender);
void __fastcall PopupMenu1Popup(TObject* Sender);
void __fastcall N1Click(TObject* Sender);
void __fastcall FormDestroy(TObject* Sender);
void __fastcall ToolButton1Click(TObject* Sender);
void __fastcall sgEditKeyDown(TObject* Sender, WORD& Key,
TShiftState Shift);
void __fastcall sgEditSelectCell(TObject* Sender, int ACol,
int ARow, bool& CanSelect);
void __fastcall Timer1Timer(TObject* Sender);
void __fastcall N4Click(TObject* Sender);
void __fastcall btTxtTypeClick(TObject* Sender);
void __fastcall ToolButton3Click(TObject* Sender);
void __fastcall btRowSaveClick(TObject* Sender);
void __fastcall btColSaveClick(TObject* Sender);
void __fastcall btRowClearClick(TObject* Sender);
void __fastcall btColClearClick(TObject* Sender);
void __fastcall ToolButton4Click(TObject* Sender);
private: // User declarations
thOpenFile* thOpen;
bool Term;
public: // User declarations
bool OpenOk;
AnsiString CurrentOpenFile;
__fastcall TFrmMain(TComponent* Owner);
void SaveToFile(const char* pszFileName);
void __fastcall OpenFileCol(AnsiString FileName, int ColIndex, int ColType);
};
//---------------------------------------------------------------------------
extern PACKAGE TFrmMain* FrmMain;
//---------------------------------------------------------------------------
#endif

View file

@ -1,124 +0,0 @@
<?xml version='1.0' encoding='utf-8' ?>
<!-- C++Builder XML Project -->
<PROJECT>
<MACROS>
<VERSION value="BCB.06.00"/>
<PROJECT value="pjDbcEditer.exe"/>
<OBJFILES value="pjDbcEditer.obj dbcedit.obj TitleFrm.obj thOpenSource.obj SearchFrm.obj"/>
<RESFILES value="pjDbcEditer.res"/>
<IDLFILES value=""/>
<IDLGENFILES value=""/>
<DEFFILE value=""/>
<RESDEPEN value="$(RESFILES) dbcedit.dfm TitleFrm.dfm SearchFrm.dfm"/>
<LIBFILES value=""/>
<LIBRARIES value=""/>
<SPARELIBS value="vcl.lib rtl.lib indy.lib"/>
<PACKAGES value="vcl.bpi rtl.bpi dbrtl.bpi adortl.bpi vcldb.bpi vclx.bpi bdertl.bpi
vcldbx.bpi ibxpress.bpi dsnap.bpi cds.bpi bdecds.bpi qrpt.bpi teeui.bpi
teedb.bpi tee.bpi dss.bpi teeqr.bpi visualclx.bpi visualdbclx.bpi
dsnapcrba.bpi dsnapcon.bpi bcbsmp.bpi vclie.bpi xmlrtl.bpi inet.bpi
inetdbbde.bpi inetdbxpress.bpi inetdb.bpi nmfast.bpi webdsnap.bpi
bcbie.bpi websnap.bpi soaprtl.bpi dclocx.bpi dbexpress.bpi dbxcds.bpi
indy.bpi bcb2kaxserver.bpi dclusr.bpi"/>
<PATHCPP value=".;"/>
<PATHPAS value=".;"/>
<PATHRC value=".;"/>
<PATHASM value=".;"/>
<DEBUGLIBPATH value="$(BCB)\lib\debug"/>
<RELEASELIBPATH value="$(BCB)\lib\release"/>
<LINKER value="ilink32"/>
<USERDEFINES value="_DEBUG"/>
<SYSDEFINES value="_RTLDLL;NO_STRICT;USEPACKAGES"/>
<MAINSOURCE value="pjDbcEditer.cpp"/>
<INCLUDEPATH value="&quot;C:\Program Files\Borland\CBuilder6\Projects&quot;;E:\moshou\dbcEdit;$(BCB)\include;$(BCB)\include\vcl"/>
<LIBPATH value="&quot;C:\Program Files\Borland\CBuilder6\Projects&quot;;E:\moshou\dbcEdit;$(BCB)\Projects\Lib;$(BCB)\lib\obj;$(BCB)\lib"/>
<WARNINGS value="-w-par"/>
<OTHERFILES value=""/>
</MACROS>
<OPTIONS>
<IDLCFLAGS value="-I&quot;C:\Program Files\Borland\CBuilder6\Projects&quot; -IE:\moshou\dbcEdit
-I$(BCB)\include -I$(BCB)\include\vcl -src_suffix cpp -D_DEBUG -boa"/>
<CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -c
-tW -tWM"/>
<PFLAGS value="-$Y+ -$W -$O- -$A8 -v -JPHNE -M"/>
<RFLAGS value=""/>
<AFLAGS value="/mx /w2 /zi"/>
<LFLAGS value="-D&quot;&quot; -aa -Tpe -x -Gn -v"/>
<OTHERFILES value=""/>
</OPTIONS>
<LINKER>
<ALLOBJ value="c0w32.obj $(PACKAGES) Memmgr.Lib sysinit.obj $(OBJFILES)"/>
<ALLRES value="$(RESFILES)"/>
<ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cp32mti.lib"/>
<OTHERFILES value=""/>
</LINKER>
<FILELIST>
<FILE FILENAME="pjDbcEditer.res" FORMNAME="" UNITNAME="pjDbcEditer.res" CONTAINERID="ResTool" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="pjDbcEditer.cpp" FORMNAME="" UNITNAME="pjDbcEditer" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="dbcedit.cpp" FORMNAME="FrmMain" UNITNAME="dbcedit" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="TitleFrm.cpp" FORMNAME="FrmTitle" UNITNAME="TitleFrm" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="thOpenSource.cpp" FORMNAME="" UNITNAME="thOpenSource" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="SearchFrm.cpp" FORMNAME="FrmSearch" UNITNAME="SearchFrm" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
</FILELIST>
<BUILDTOOLS>
</BUILDTOOLS>
<IDEOPTIONS>
[Version Info]
IncludeVerInfo=0
AutoIncBuild=0
MajorVer=1
MinorVer=0
Release=0
Build=0
Debug=0
PreRelease=0
Special=0
Private=0
DLL=0
Locale=2052
CodePage=936
[Version Info Keys]
CompanyName=
FileDescription=
FileVersion=1.0.0.0
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=1.0.0.0
Comments=
[Debugging]
DebugSourceDirs=$(BCB)\source\vcl
[Parameters]
RunParams=
Launcher=
UseLauncher=0
DebugCWD=
HostApplication=
RemoteHost=
RemotePath=
RemoteLauncher=
RemoteCWD=
RemoteDebug=0
[Compiler]
ShowInfoMsgs=0
LinkDebugVcl=0
LinkCGLIB=0
[CORBA]
AddServerUnit=1
AddClientUnit=1
PrecompiledHeaders=1
[Language]
ActiveLang=
ProjectLang=
RootDir=
</IDEOPTIONS>
</PROJECT>

View file

@ -1,37 +0,0 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("dbcedit.cpp", FrmMain);
USEFORM("TitleFrm.cpp", FrmTitle);
USEFORM("SearchFrm.cpp", FrmSearch);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TFrmMain), &FrmMain);
Application->CreateForm(__classid(TFrmTitle), &FrmTitle);
Application->CreateForm(__classid(TFrmSearch), &FrmSearch);
Application->Run();
}
catch (Exception& exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception& exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,188 +0,0 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "thOpenSource.h"
#include "dbcedit.h"
#include "stdio.h"
#include <dir.h>
#include <inifiles.hpp>
#include <process.h>
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall thOpenFile::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall thOpenFile::thOpenFile(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall thOpenFile::Execute()
{
//---- Place thread code here ----
//if(!Terminated){
// FrmMain->LoadAndModify(FrmMain->OpenDialog1->FileName.c_str());
// FrmMain->OpenOk=true;
//}
thEnd = false;
RunOpen();
FrmMain->OpenOk = true;
thEnd = true;
}
//---------------------------------------------------------------------------
void __fastcall thOpenFile::RunOpen()
{
LoadAndModify(FrmMain->OpenDialog1->FileName.c_str());
//OpenOk=true;
}
void thOpenFile::ReadAndModifyFromBuff(char* pBuff, DWORD dwSize, const char* pszFileName)
{
char szErrorMsg[MAX_PATH];
char szNewFileName[MAX_PATH];
DWORD w;
TIniFile* ini;
TypePtr p(pBuff);
if ('WDBC' != TAG(*p.dw))
{
_snprintf(szErrorMsg, 512, "[%s]Not Wow's dbc file!", pszFileName);
ShowMessage(szErrorMsg);
return;
}
p.dw++;
DWORD dwRows, dwCols, dwRowLen, dwTextLen;
dwRows = *p.dw++;
dwCols = *p.dw++;
dwRowLen = *p.dw++;
dwTextLen = *p.dw++;
FrmMain->sgEdit->RowCount = dwRows + 1;
FrmMain->sgEdit->ColCount = dwCols + 1;
for (int i = 0; i < FrmMain->sgEdit->RowCount; i++)
{
FrmMain->sgEdit->Cells[0][i] = IntToStr(i);
if (Terminated) return;
}
//设定列标题
AnsiString iniSetFile = ExtractFilePath(Application->ExeName) + "BcdEditer.ini";
AnsiString SectionName = ExtractFileName(FrmMain->CurrentOpenFile);
ini = new TIniFile(iniSetFile);
for (int j = 0; j < FrmMain->sgEdit->ColCount; j++)
{
FrmMain->sgEdit->Cells[j][0] = ini->ReadString(SectionName, "ColTitle" + IntToStr(j), IntToStr(j));
//sgEdit->Cells[j][0]=IntToStr(j);
ColType[j] = ini->ReadInteger(SectionName, "ColType" + IntToStr(j), 0);
if (Terminated) return;
}
delete ini;
//int *ColType = new int[dwCols];
DWORD dwTextStartPos = dwRows * dwRowLen + 20;
char* pTextPtr = pBuff + dwTextStartPos;
char pszTemp[MAX_PATH];
float fTemp;
long lTemp;
DWORD i, j;
BOOL* pbString = new BOOL[dwRows * dwCols];
float newTmp;
//int ColType;
ini = new TIniFile(iniSetFile);
for (i = 0; i < dwRows; i++)
{
for (j = 0; j < dwCols; j++)
{
//SleepEx(0,0);
if (Terminated) return;
lTemp = *p.l;
newTmp = *p.f;
memcpy(&fTemp, &newTmp, 4);
if (j == 0) //ID
FrmMain->sgEdit->Cells[j + 1][i + 1] = IntToStr(lTemp);
else
{
//ColType= ini->ReadInteger(SectionName,"ColType"+IntToStr(j),0);
switch (ColType[j + 1])
{
case 0: //整型
FrmMain->sgEdit->Cells[j + 1][i + 1] = IntToStr(lTemp);
break;
case 1: //浮点
FrmMain->sgEdit->Cells[j + 1][i + 1] = FloatToStr(fTemp);
break;
case 2: //文本 文本类型只能看,不能编辑
if (dwTextStartPos + lTemp < dwSize)
{
pTextPtr = pBuff + dwTextStartPos + lTemp;
FrmMain->sgEdit->Cells[j + 1][i + 1] = pTextPtr;
}
else
{
FrmMain->sgEdit->Cells[j + 1][i + 1] = "该列不是文本";
}
break;
default: //整型
FrmMain->sgEdit->Cells[j + 1][i + 1] = IntToStr(lTemp);
}
}
p.c += 4;
}
}
delete [] pbString;
//delete [] ColType;
delete ini;
}
void thOpenFile::LoadAndModify(const char* pszFileName)
{
HANDLE hFile = NULL;
hFile = CreateFile(pszFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)return;
DWORD r = 0, nFileSize = 0;
nFileSize = GetFileSize(hFile, NULL);
char* pTmpBuf = new char[nFileSize];
if (pTmpBuf == NULL)
{
CloseHandle(hFile);
return;
}
ReadFile(hFile, pTmpBuf, nFileSize, &r, NULL);
FrmMain->CurrentOpenFile = pszFileName;
FrmMain->btSave->Enabled = true;
ReadAndModifyFromBuff(pTmpBuf, nFileSize, pszFileName);
//SAFE_DELETE_ARRAY(pTmpBuf);
delete [] pTmpBuf;
CloseHandle(hFile);
}

View file

@ -1,24 +0,0 @@
//---------------------------------------------------------------------------
#ifndef thOpenSourceH
#define thOpenSourceH
//---------------------------------------------------------------------------
#include <Classes.hpp>
//---------------------------------------------------------------------------
class thOpenFile : public TThread
{
private:
protected:
void __fastcall Execute();
void __fastcall RunOpen();
public:
bool thEnd;
int ColType[10000];
__fastcall thOpenFile(bool CreateSuspended);
void LoadAndModify(const char* pszFileName);
void ReadAndModifyFromBuff(char* pBuff, DWORD dwSize, const char* pszFileName);
};
//---------------------------------------------------------------------------
#endif

Binary file not shown.

View file

@ -1,241 +0,0 @@
ENTRY ItemSetEntry
UNUSED INDEX setid
UNUSED STR setname
UNKNOWN[7]
UNUSED UINT flags//, const
UNUSED UINT required_item_id[8]
UNKNOWN[48]
UINT spells[8]
UINT items_to_triggerspell[8] //items_to_triggerspell[0] -- for spells[0]
UINT required_skill_id//only 2 items sets have requirements
UINT required_skill_value
ENDENTRY
ENTRY TalentEntry
INDEX TalentID
UINT TalentTree
UNKNOWN [2]
UINT RankID[5]
UNKNOWN[12]
ENDENTRY
ENTRY emoteentry
INDEX Id
UNUSED STR name
UINT textid
UNUSED UINT textid2
UNUSED UINT textid3
UNUSED UINT textid4
UNKNOWN
UNUSED UINT textid5
UNKNOWN
UNUSED UINT textid6
UNKNOWN[9]
ENDENTRY
ENTRY SpellEntry
INDEX Id
UINT School
UNKNOWN [2]
UINT Category
UNKNOWN
UINT Attributes
UINT AttributesEx
UNKNOWN [3]
UINT Targets
UINT TargetCreatureType
UINT RequiresSpellFocus
UNKNOWN
UINT CasterAuraState
UINT CastingTimeIndex
UINT RecoveryTime
UINT CategoryRecoveryTime
UINT InterruptFlags
UINT AuraInterruptFlags
UINT ChannelInterruptFlags
UINT procFlags
UINT procChance
UINT procCharges
UINT maxLevel
UINT baseLevel
UINT spellLevel
UINT DurationIndex
UINT powerType
UINT manaCost
UINT manaCostPerlevel
UINT manaPerSecond
UINT manaPerSecondPerLevel
UINT rangeIndex
FLOAT speed
UINT modalNextSpell
UNKNOWN
UINT Totem[2]
UINT Reagent[8]
UINT ReagentCount[8]
UINT EquippedItemClass
UINT EquippedItemSubClass
UINT Effect[3] // 59 - 61
UINT EffectDieSides[3]
UINT EffectBaseDice[3]
FLOAT EffectDicePerLevel[3]
FLOAT EffectRealPointsPerLevel[3]
INT EffectBasePoints[3] // 74 - 76
UNKNOWN [3]
UINT EffectImplicitTargetA[3] // 80 - 82
UINT EffectImplicitTargetB[3] // 83 - 85
UINT EffectRadiusIndex[3]
UINT EffectApplyAuraName[3] // 89 - 91
UINT EffectAmplitude[3]
UINT Effectunknown[3]
UINT EffectChainTarget[3]
UINT EffectItemType[3]
UINT EffectMiscValue[3] // 104 - 106
UINT EffectTriggerSpell[3]
FLOAT EffectPointsPerComboPoint[3]
UINT SpellVisual
UNKNOWN
UINT SpellIconID
UINT activeIconID
UINT spellPriority
UNUSED STR Name
UNUSED STR NameAlt1
UNUSED STR NameAlt2
UNUSED STR NameAlt3
UNUSED STR NameAlt4
UNUSED STR NameAlt5
UNUSED STR NameAlt6
UNUSED STR NameAlt7
UNUSED STR NameFlags
UINT Rank
UINT RankAlt1
UINT RankAlt2
UINT RankAlt3
UINT RankAlt4
UINT RankAlt5
UINT RankAlt6
UINT RankAlt7
UINT RankFlags
UNUSED STR Description
UNUSED STR DescriptionAlt1
UNUSED STR DescriptionAlt2
UNUSED STR DescriptionAlt3
UNUSED STR DescriptionAlt4
UNUSED STR DescriptionAlt5
UNUSED STR DescriptionAlt6
UNUSED STR DescriptionAlt7
UNUSED UINT DescriptionFlags
UNUSED STR BuffDescription
UNUSED STR BuffDescriptionAlt1
UNUSED STR BuffDescriptionAlt2
UNUSED STR BuffDescriptionAlt3
UNUSED STR BuffDescriptionAlt4
UNUSED STR BuffDescriptionAlt5
UNUSED STR BuffDescriptionAlt6
UNUSED STR BuffDescriptionAlt7
UINT ManaCostPercentage
UINT StartRecoveryCategory
UINT StartRecoveryTime
UINT field156 //nice name
UNKNOWN[2]
UINT SpellFamilyName
UNKNOWN[11]
ENDENTRY
ENTRY SpellCastTime
INDEX ID
UINT CastTime
UNKNOWN[2]
ENDENTRY
ENTRY SpellRadius
INDEX ID
FLOAT Radius
UNKNOWN
FLOAT Radius2
ENDENTRY
ENTRY SpellRange
INDEX ID
FLOAT minRange
FLOAT maxRange
UNKNOWN[18]
UNKNOWN//some flag
ENDENTRY
ENTRY SpellDuration
INDEX ID
UINT Duration1
UINT Duration2
UINT Duration3
ENDENTRY
ENTRY AreaTableEntry
UINT ID
UNUSED UINT map
UINT zone
INDEX exploreFlag
UNKNOWN[6]
UINT area_level
UNUSED STR name
UNKNOWN[9]
ENDENTRY
ENTRY FactionEntry
INDEX ID
INT reputationListID
UNKNOWN[7]
UINT something1
UINT something2
UINT something3
UINT something4
UINT something5
UINT something6
UINT something7
UINT something8
UINT something9
UINT faction
UNUSED STR name
UNKNOWN[17]
ENDENTRY
ENTRY FactionTemplateEntry
INDEX ID
UINT faction
UNKNOWN
UINT fightsupport
UINT friendly
UINT hostile
UNKNOWN[8]
ENDENTRY
ENTRY ItemDisplayTemplateEntry
UINT ID
UNUSED STR modelFile
UNKNOWN
UNUSED STR imageFile
UNKNOWN
UNUSED STR invImageFile
UNKNOWN[5]
UINT seed
UNKNOWN [10]
UINT randomPropertyID
ENDENTRY

View file

@ -1,36 +0,0 @@
# This code is part of MaNGOS. Contributor & Copyright details are in AUTHORS/THANKS.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
cmake_minimum_required (VERSION 2.8)
INCLUDE(cmake/FindMySQL.cmake)
INCLUDE(cmake/FindPostgreSQL.cmake)
MESSAGE("-- Check PostgreSQL")
FIND_PGSQL()
ADD_DEFINITIONS(-DDO_POSTGRESQL)
MESSAGE("-- Check MySQL")
FIND_MYSQL()
ADD_DEFINITIONS(-DDO_MYSQL)
INCLUDE_DIRECTORIES(${MYSQL_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${PGSQL_INCLUDE_DIR})
ADD_EXECUTABLE (mysql2pgsql src/main.cpp)
TARGET_LINK_LIBRARIES(mysql2pgsql ${PGSQL_LIBRARIES})
TARGET_LINK_LIBRARIES(mysql2pgsql ${MYSQL_LIBRARIES})

View file

@ -1,13 +0,0 @@
Using cmake on a Windows
------------------
1. install cmake (http://www.cmake.org/cmake/resources/software.html)
2. cmake -i
3. Project.sln
4. {Debug/Release}/mysql2pgsql.exe
Using cmake on a Unix/Linux
------------------
1. install cmake
2. cmake -i
3. make
4. ./mysql2pgsql

View file

@ -1,68 +0,0 @@
# - Find mysqlclient
# Find the native MySQL includes and library
#
# MYSQL_INCLUDE_DIR - where to find mysql.h, etc.
# MYSQL_LIBRARIES - List of libraries when using MySQL.
# MYSQL_FOUND - True if MySQL found.
MACRO(FIND_MYSQL)
IF (MYSQL_INCLUDE_DIR)
# Already in cache, be silent
SET(MySQL_FIND_QUIETLY TRUE)
ENDIF (MYSQL_INCLUDE_DIR)
FIND_PATH(MYSQL_INCLUDE_DIR mysql.h
$ENV{ProgramFiles}/MySQL/*/include
$ENV{SystemDrive}/MySQL/*/include
/usr/local/mysql/include
/usr/local/include/mysql
/usr/local/include
/usr/include/mysql
/usr/include
/usr/mysql/include
)
IF(MSVC)
SET(MYSQL_NAMES libmysql)
ELSE(MSVC)
SET(MYSQL_NAMES mysqlclient mysqlclient_r)
ENDIF(MSVC)
SET(MYSQL_SEARCH_LIB_PATHS
$ENV{ProgramFiles}/MySQL/*/lib/opt
$ENV{SystemDrive}/MySQL/*/lib/opt
/usr/local/mysql/lib
/usr/local/lib/mysql
/usr/local/lib
/usr/lib/mysql
/usr/lib
)
FIND_LIBRARY(MYSQL_LIBRARY
NAMES ${MYSQL_NAMES}
PATHS ${MYSQL_SEARCH_LIB_PATHS}
)
IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
SET(MYSQL_FOUND TRUE)
SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} )
ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
SET(MYSQL_FOUND FALSE)
SET( MYSQL_LIBRARIES )
ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
IF (MYSQL_FOUND)
IF (NOT MySQL_FIND_QUIETLY)
MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}")
ENDIF (NOT MySQL_FIND_QUIETLY)
ELSE (MYSQL_FOUND)
IF (MySQL_FIND_REQUIRED)
MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.")
MESSAGE(FATAL_ERROR "Could NOT find MySQL library")
ENDIF (MySQL_FIND_REQUIRED)
ENDIF (MYSQL_FOUND)
MARK_AS_ADVANCED(
MYSQL_LIBRARY
MYSQL_INCLUDE_DIR
)
ENDMACRO(FIND_MYSQL)

View file

@ -1,67 +0,0 @@
# - Find libpq
# Find the native PostgreSQL includes and library
#
# PGSQL_INCLUDE_DIR - where to find libpq-fe.h, etc.
# PGSQL_LIBRARIES - List of libraries when using PGSQL.
# PGSQL_FOUND - True if PGSQL found.
MACRO(FIND_PGSQL)
IF (PGSQL_INCLUDE_DIR)
# Already in cache, be silent
SET(PostgreSQL_FIND_QUIETLY TRUE)
ENDIF (PGSQL_INCLUDE_DIR)
FIND_PATH(PGSQL_INCLUDE_DIR libpq-fe.h
$ENV{ProgramFiles}/PostgreSQL/*/include
$ENV{SystemDrive}/PostgreSQL/*/include
/usr/local/pgsql/include
/usr/local/postgresql/include
/usr/local/include/pgsql
/usr/local/include/postgresql
/usr/local/include
/usr/include/pgsql
/usr/include/postgresql
/usr/include
/usr/pgsql/include
/usr/postgresql/include
)
SET(PGSQL_NAMES pq libpq)
SET(PGSQL_SEARCH_LIB_PATHS
${PGSQL_SEARCH_LIB_PATHS}
$ENV{ProgramFiles}/PostgreSQL/*/lib
$ENV{SystemDrive}/PostgreSQL/*/lib
/usr/local/pgsql/lib
/usr/local/lib
/usr/lib
)
FIND_LIBRARY(PGSQL_LIBRARY
NAMES ${PGSQL_NAMES}
PATHS ${PGSQL_SEARCH_LIB_PATHS}
)
IF (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY)
SET(PGSQL_FOUND TRUE)
SET( PGSQL_LIBRARIES ${PGSQL_LIBRARY} )
ELSE (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY)
SET(PGSQL_FOUND FALSE)
SET( PGSQL_LIBRARIES )
ENDIF (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY)
IF (PGSQL_FOUND)
IF (NOT PostgreSQL_FIND_QUIETLY)
MESSAGE(STATUS "Found PostgreSQL: ${PGSQL_LIBRARY}")
ENDIF (NOT PostgreSQL_FIND_QUIETLY)
ELSE (PGSQL_FOUND)
IF (PostgreSQL_FIND_REQUIRED)
MESSAGE(STATUS "Looked for PostgreSQL libraries named ${PGSQL_NAMES}.")
MESSAGE(FATAL_ERROR "Could NOT find PostgreSQL library")
ENDIF (PostgreSQL_FIND_REQUIRED)
ENDIF (PGSQL_FOUND)
MARK_AS_ADVANCED(
PGSQL_LIBRARY
PGSQL_INCLUDE_DIR
)
ENDMACRO(FIND_PGSQL)

View file

@ -1,183 +0,0 @@
/**
* This code is part of MaNGOS. Contributor & Copyright details are in AUTHORS/THANKS.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _DEFINES_
#define _DEFINES_
#ifdef WIN32
#include <winsock2.h>
#pragma warning(disable:4996)
#endif
#include <libpq-fe.h>
#include <mysql.h>
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <string.h>
using namespace std;
#ifdef WIN32
typedef unsigned __int64 uint64;
typedef unsigned int uint32;
#else
#include <stdint.h>
#ifndef uint64_t
#include <unistd.h>
#endif
typedef uint64_t uint64;
typedef unsigned int uint32;
#endif
struct sField
{
string name; // field name
string def; // field default data
string type; // field type
uint32 flags; // filed flags, see field flags;
};
typedef vector<sField> T_Table;
typedef vector<string> T_TableList;
typedef map< string, T_Table > TDataBase;
static
void pg_notice(void* arg, const char* message)
{
/// Do nothing
//printf("%s\n", message);
}
inline
string ConvertNativeType(enum_field_types mysqlType, uint32 length)
{
switch (mysqlType)
{
case FIELD_TYPE_TIMESTAMP:
return "timestamp";
case FIELD_TYPE_BIT:
return "bit(1)";
case FIELD_TYPE_DATETIME:
return "date";
case FIELD_TYPE_YEAR:
case FIELD_TYPE_BLOB:
case FIELD_TYPE_SET:
case FIELD_TYPE_NULL:
case FIELD_TYPE_ENUM:
return "text";
case FIELD_TYPE_TINY:
case FIELD_TYPE_SHORT:
case FIELD_TYPE_INT24:
return "integer";
case FIELD_TYPE_LONGLONG:
case FIELD_TYPE_LONG:
{
string temp;
char str[10];
temp = "numeric";
if (length)
{
temp.append("(");
sprintf(str, "%d", length);
temp.append(str);
temp.append(")");
}
return temp;
}
case FIELD_TYPE_DECIMAL:
case FIELD_TYPE_FLOAT:
case FIELD_TYPE_DOUBLE:
return "float";
case FIELD_TYPE_STRING:
{
string temp;
char str[10];
temp = "char";
if (length)
{
temp.append("(");
sprintf(str, "%d", length);
temp.append(str);
temp.append(")");
}
return temp;
}
case FIELD_TYPE_VAR_STRING:
{
string temp;
char str[10];
temp = "varchar";
if (length)
{
temp.append("(");
sprintf(str, "%d", length);
temp.append(str);
temp.append(")");
}
return temp;
}
default:
return "text";
}
return "text";
}
inline
bool IsNeeedEscapeString(enum_field_types mysqlType)
{
switch (mysqlType)
{
case FIELD_TYPE_VAR_STRING:
case FIELD_TYPE_STRING:
case FIELD_TYPE_TINY_BLOB:
case FIELD_TYPE_MEDIUM_BLOB:
case FIELD_TYPE_LONG_BLOB:
case FIELD_TYPE_BLOB:
return true;
default:
return false;
}
return false;
}
inline
void PG_Exec_str(string sql, PGconn* mPGconn)
{
PGresult* res = PQexec(mPGconn, sql.c_str());
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("SQL: %s", sql.c_str());
printf("SQL %s", PQerrorMessage(mPGconn));
}
}
void PG_Escape_Str(string& str)
{
if (str.empty())
return;
char* buf = new char[str.size() * 2 + 1];
PQescapeString(buf, str.c_str(), str.size());
str = buf;
delete[] buf;
}
#endif

View file

@ -1,338 +0,0 @@
/**
* This code is part of MaNGOS. Contributor & Copyright details are in AUTHORS/THANKS.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "defines.h"
int main(int argc, char* argv[])
{
char sPGhost[26], sPGport[26], sPGdb[26], sPGuser[26], sPGpass[26];
printf("Postgres connection settings\n Host>");
scanf("%s", sPGhost);
printf(" Port>");
scanf("%s", sPGport);
printf(" Base>");
scanf("%s", sPGdb);
printf(" User>");
scanf("%s", sPGuser);
printf(" Pass>");
scanf("%s", sPGpass);
///////////////////////////////
///////PGSQL Connect///////////
///////////////////////////////
PGconn* mPGconn = NULL;
mPGconn = PQsetdbLogin(sPGhost, sPGport, NULL, NULL, sPGdb, sPGuser, sPGpass);
if (PQstatus(mPGconn) != CONNECTION_OK)
{
printf("Could not connect to Postgre database at [%s]: \n %s\n", sPGhost, PQerrorMessage(mPGconn));
PQfinish(mPGconn);
return 1;
}
else
{
printf("Connected to Postgre database at [%s]\n", sPGhost);
printf(" PostgreSQL server ver: [%d]\n\n", PQserverVersion(mPGconn));
}
/// Set dummy notice processor
PQsetNoticeProcessor(mPGconn, pg_notice, mPGconn);
///////////////////////////////
///////MySQL Connect///////////
///////////////////////////////
MYSQL* mysqlInit;
mysqlInit = mysql_init(NULL);
if (!mysqlInit)
{
printf("Could not initialize Mysql connection\n");
return 1;
}
char sMYhost[26], sMYdb[26], sMYuser[26], sMYpass[26];
int iMYport;
printf("Mysql connection settings \n Host>");
scanf("%s", sMYhost);
printf(" Port>");
scanf("%d", &iMYport);
printf(" Base>");
scanf("%s", sMYdb);
printf(" User>");
scanf("%s", sMYuser);
printf(" Pass>");
scanf("%s", sMYpass);
mysql_options(mysqlInit, MYSQL_SET_CHARSET_NAME, "utf8");
MYSQL* mMysql;
mMysql = mysql_real_connect(mysqlInit, sMYhost, sMYuser, sMYpass, sMYdb, iMYport, NULL, 0);
if (mMysql)
{
printf("Connected to MySQL database at [%s] \n", sMYhost);
printf(" MySQL client library: [%s] \n", mysql_get_client_info());
printf(" MySQL server ver: [%s] \n\n", mysql_get_server_info(mMysql));
}
else
{
printf("Could not connect to MySQL database at [%s]:\n %s\n", sMYhost , mysql_error(mysqlInit));
mysql_close(mysqlInit);
return 1;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
MYSQL_RES* result = NULL;
MYSQL_ROW row;
MYSQL_FIELD* fields = NULL;
uint64 rowCount = 0;
uint32 fieldCount = 0;
result = mysql_list_tables(mMysql , NULL);
rowCount = mysql_num_rows(result);
/***********************/
/* get list of tables */
/***********************/
T_TableList mTableList;
mTableList.reserve((size_t)rowCount);
while ((row = mysql_fetch_row(result)) != NULL)
{
for (uint32 i = 0; i < mysql_num_fields(result); i++)
{
mTableList.push_back(row[i]);
}
}
mysql_free_result(result);
/****************************************/
/* convert filed type and default type */
/****************************************/
T_Table m_Table;
TDataBase m_DataBase_Map;
m_DataBase_Map.clear();
for (uint32 j = 0; j < mTableList.size(); ++j)
{
result = mysql_list_fields(mMysql, mTableList[j].c_str(), NULL);
fieldCount = mysql_num_fields(result);
fields = mysql_fetch_fields(result);
for (uint32 i = 0; i < fieldCount; ++i)
{
sField mfield;
mfield.name = fields[i].name;
if (!fields[i].def)
{
mfield.def = "NULL";
}
else if (!strcmp(fields[i].def, "0000-00-00 00:00:00"))
{
/// Convert MySQL Default timestamp to PGSQL Default timestamp
mfield.def.append("'1970-01-01 00:00:00'");
}
else
{
/// Append '
mfield.def.append("'");
mfield.def.append(fields[i].def);;
mfield.def.append("'");
}
mfield.type = ConvertNativeType(fields[i].type, fields[i].length);
mfield.flags = fields[i].flags;
m_Table.push_back(mfield);
}
m_DataBase_Map[mTableList[j]] = m_Table;
m_Table.clear();
mysql_free_result(result);
}
/******************************************/
/* Conversion of the layout of the tables */
/******************************************/
uint32 count = 0;
TDataBase::const_iterator citr;
for (citr = m_DataBase_Map.begin(); citr != m_DataBase_Map.end(); ++citr)
{
ostringstream sql_str;
sql_str << "DROP TABLE IF EXISTS " << (*citr).first.c_str() << ";\n";
sql_str << "CREATE TABLE " << (*citr).first.c_str() << "(\n";
T_Table::const_iterator v_iter;
ostringstream prim_key_str;
ostringstream index_str;
for (v_iter = (*citr).second.begin();
v_iter != (*citr).second.end();
++v_iter)
{
sql_str << " " << (*v_iter).name;
if (((*v_iter).flags & AUTO_INCREMENT_FLAG) != 0)
{
/// AUTO_INCREMENT fields not have "default" data
sql_str << " bigserial";
}
else
{
sql_str << " " << (*v_iter).type;
sql_str << " default " << (*v_iter).def;
}
/// IF column have PRIMARY KEY flag then use column in PRIMARY KEY
if (IS_PRI_KEY((*v_iter).flags) != 0)
{
if (prim_key_str.str().size())
prim_key_str << ", ";
else
{
prim_key_str << "ALTER TABLE ";
prim_key_str << (*citr).first.c_str();
prim_key_str << " ADD CONSTRAINT pk_";
prim_key_str << (*citr).first.c_str();
prim_key_str << "_";
prim_key_str << (*v_iter).name;
prim_key_str << " PRIMARY KEY (";
}
prim_key_str << (*v_iter).name;
}
else if (((*v_iter).flags & MULTIPLE_KEY_FLAG) != 0)
{
/// IF column have INDEX flag then create INDEX
index_str << "CREATE INDEX idx_";
index_str << (*citr).first.c_str();
index_str << "_";
index_str << (*v_iter).name;
index_str << " ON ";
index_str << (*citr).first.c_str();
index_str << " USING btree (";
index_str << (*v_iter).name;
index_str << ");\n";
}
else if (((*v_iter).flags & UNIQUE_KEY_FLAG) != 0)
{
/// IF column have UNIQUE INDEX flag then create INDEX
index_str << "CREATE UNIQUE INDEX uidx_";
index_str << (*citr).first.c_str();
index_str << "_";
index_str << (*v_iter).name;
index_str << " ON ";
index_str << (*citr).first.c_str();
index_str << " USING btree (";
index_str << (*v_iter).name;
index_str << ");\n";
}
/// don't output "," for last column
if (v_iter + 1 != (*citr).second.end())
sql_str << ",\n";
else
sql_str << "\n";
}
sql_str << ")\n";
/// Out Table structure
PG_Exec_str(sql_str.str(), mPGconn);
/// out PRIMARY KEY
if (prim_key_str.str().size())
{
prim_key_str << ")";
PG_Exec_str(prim_key_str.str(), mPGconn);
}
/// out INDEX's
if (index_str.str().size())
PG_Exec_str(index_str.str(), mPGconn);
++count;
printf("Convert [%d] tables...\r", count);
}
printf("Completed the conversion of [%d] tables!\n", count);
/****************/
/* Copying data */
/****************/
count = 0;
for (uint32 j = 0; j < mTableList.size(); ++j)
{
ostringstream sql_str;
sql_str << "SELECT * FROM ";
sql_str << mTableList[j].c_str();
if (mysql_query(mysqlInit, sql_str.str().c_str()))
continue;
if (!(result = mysql_store_result(mysqlInit)))
continue;
while ((row = mysql_fetch_row(result)) != NULL)
{
ostringstream insert_str;
insert_str << "INSERT INTO ";
insert_str << mTableList[j].c_str();
insert_str << " VALUES (";
fieldCount = mysql_num_fields(result);
fields = mysql_fetch_fields(result);
for (uint32 i = 0 ; i < fieldCount ; ++i)
{
if (!row[i])
insert_str << "NULL";
else
{
if (IsNeeedEscapeString(fields[i].type))
{
string field_str = row[i];
PG_Escape_Str(field_str);
insert_str << "E'";
insert_str << field_str.c_str();
insert_str << "'";
}
else if (!strcmp(row[i], "0000-00-00 00:00:00"))
{
/// Convert MySQL timestamp to PGSQL timestamp
insert_str << "'1970-01-01 00:00:00'";
}
else
{
insert_str << "'";
insert_str << row[i];
insert_str << "'";
}
}
/// don't output "," for last column
if (i + 1 != fieldCount)
insert_str << ",";
else
insert_str << ")\n";
}
PG_Exec_str(insert_str.str(), mPGconn);
}
mysql_free_result(result);
++count;
printf("Copied data from [%d] tables...\r", count);
}
printf("Finished copying the data from [%d] tables!\n", count);
mTableList.clear();
m_DataBase_Map.clear();
/// Close connections
mysql_close(mMysql);
PQfinish(mPGconn);
printf("end\n");
return 0;
}